From 9a95807148c5fbec3c32d94b7461792362147f78 Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Fri, 26 Apr 2024 14:30:38 +0200 Subject: [PATCH 1/7] ci: Add periphery scan script --- .mise.toml | 3 ++- .periphery.yml | 19 +++++++++++++++++++ scripts/periphery.sh | 24 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 .periphery.yml create mode 100755 scripts/periphery.sh diff --git a/.mise.toml b/.mise.toml index f412386bf..d2731f7b4 100644 --- a/.mise.toml +++ b/.mise.toml @@ -1,4 +1,5 @@ [tools] tuist = '4.9.0' swiftformat = '0.53.7' -swiftlint = '0.54.0' \ No newline at end of file +swiftlint = '0.54.0' +Periphery = '2.18.0' \ No newline at end of file diff --git a/.periphery.yml b/.periphery.yml new file mode 100644 index 000000000..6e4d22d0a --- /dev/null +++ b/.periphery.yml @@ -0,0 +1,19 @@ +clean_build: true +retain_objc_accessible: true +retain_public: true +schemes: +- Infomaniak Mail +- MailAppIntentsExtension +- MailCore +- MailCoreUI +- MailNotificationServiceExtension +- MailResources +- MailShareExtension +targets: +- Infomaniak Mail +- MailAppIntentsExtension +- MailCore +- MailNotificationServiceExtension +- MailResources +- MailShareExtension +workspace: Mail.xcworkspace diff --git a/scripts/periphery.sh b/scripts/periphery.sh new file mode 100755 index 000000000..e93f41c79 --- /dev/null +++ b/scripts/periphery.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +#tuist install +#tuist generate -n + + +# Check if the "--full-dir" argument is provided +if [[ "$1" == "--full-dir" ]]; then + full_dir=true +else + full_dir=false +fi + +# Perform the periphery scan and handle directory removal based on argument +if "$full_dir"; then + detailedOutput=$(periphery scan --quiet) +else + detailedOutput=$(periphery scan --quiet | sed "s|$(pwd)/||g") +fi + +unusedCount=$(wc -l <<< "$detailedOutput" | tr -d '[:space:]') + +echo "$detailedOutput" +echo "Total unused instances $unusedCount" From 900468cf7b8d2c3f94891307bbe3ecba8659bcfb Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Fri, 26 Apr 2024 15:00:20 +0200 Subject: [PATCH 2/7] ci: Run periphery scan workflow --- .github/workflows/periphery.yml | 23 +++++++++++++++++++++++ .mise.toml | 2 +- scripts/periphery.sh | 6 ++++-- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/periphery.yml diff --git a/.github/workflows/periphery.yml b/.github/workflows/periphery.yml new file mode 100644 index 000000000..baaa88628 --- /dev/null +++ b/.github/workflows/periphery.yml @@ -0,0 +1,23 @@ +name: CI workflow + +on: + pull_request: + branches: [ master ] + +jobs: + build: + name: Scan unused code + runs-on: [ self-hosted, iOS ] + + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.12.1 + with: + access_token: ${{ github.token }} + - uses: jdx/mise-action@v2 + with: + cache: false + - name: Checkout + uses: actions/checkout@v2 + - name: Periphery + run: ./scripts/periphery.sh diff --git a/.mise.toml b/.mise.toml index d2731f7b4..cb1466422 100644 --- a/.mise.toml +++ b/.mise.toml @@ -2,4 +2,4 @@ tuist = '4.9.0' swiftformat = '0.53.7' swiftlint = '0.54.0' -Periphery = '2.18.0' \ No newline at end of file +periphery = '2.18.0' \ No newline at end of file diff --git a/scripts/periphery.sh b/scripts/periphery.sh index e93f41c79..286f7f12c 100755 --- a/scripts/periphery.sh +++ b/scripts/periphery.sh @@ -1,7 +1,9 @@ #!/bin/bash -#tuist install -#tuist generate -n +eval "$($HOME/.local/bin/mise activate -C $SRCROOT bash --shims)" + +tuist install +tuist generate -n # Check if the "--full-dir" argument is provided From fdc81fc4a3f8ee8b76375183d26d50644e976956 Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Fri, 26 Apr 2024 15:37:34 +0200 Subject: [PATCH 3/7] ci: Correct periphery name --- .mise.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mise.toml b/.mise.toml index cb1466422..ba46e2475 100644 --- a/.mise.toml +++ b/.mise.toml @@ -1,5 +1,5 @@ [tools] tuist = '4.9.0' +periphery = '2.18.0' swiftformat = '0.53.7' swiftlint = '0.54.0' -periphery = '2.18.0' \ No newline at end of file From ea915a096cddbf1d8f7e150cb45753087333b273 Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Fri, 26 Apr 2024 15:39:31 +0200 Subject: [PATCH 4/7] ci: Stop caching mise --- .github/workflows/ci.yml | 2 ++ .github/workflows/uitests.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5929cb615..6b7479ebb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,8 @@ jobs: with: access_token: ${{ github.token }} - uses: jdx/mise-action@v2 + with: + cache: false - name: Checkout uses: actions/checkout@v2 - name: Create test env diff --git a/.github/workflows/uitests.yml b/.github/workflows/uitests.yml index 3f02f0a8d..e5e270b13 100644 --- a/.github/workflows/uitests.yml +++ b/.github/workflows/uitests.yml @@ -15,6 +15,8 @@ jobs: with: access_token: ${{ github.token }} - uses: jdx/mise-action@v2 + with: + cache: false - name: Checkout uses: actions/checkout@v2 - name: Create test env From d5feb5f93c6df5b764686f8a68ca1b256fac8005 Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Mon, 29 Apr 2024 08:18:27 +0200 Subject: [PATCH 5/7] feat: Comment after running script --- .github/workflows/periphery.yml | 12 ++++++++++++ scripts/periphery.sh | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/.github/workflows/periphery.yml b/.github/workflows/periphery.yml index baaa88628..7d35025b7 100644 --- a/.github/workflows/periphery.yml +++ b/.github/workflows/periphery.yml @@ -20,4 +20,16 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Periphery + id: periphery run: ./scripts/periphery.sh + - uses: mshick/add-pr-comment@v2 + with: + message: | + Found ${{ steps.periphery.outputs.unused_count }} unused code occurences +
+ Expand + + ``` + ${{ steps.periphery.outputs.detailed_output }} + ``` +
diff --git a/scripts/periphery.sh b/scripts/periphery.sh index 286f7f12c..19c1b3965 100755 --- a/scripts/periphery.sh +++ b/scripts/periphery.sh @@ -24,3 +24,10 @@ unusedCount=$(wc -l <<< "$detailedOutput" | tr -d '[:space:]') echo "$detailedOutput" echo "Total unused instances $unusedCount" + +# Output script result to GITHUB_OUTPUT to get it in next step +echo 'detailed_output<> $GITHUB_OUTPUT +echo "$detailedOutput" >> $GITHUB_OUTPUT +echo 'EOF' >> $GITHUB_OUTPUT + +echo "unused_count=$unusedCount" >> $GITHUB_OUTPUT From 4ada2302ab92b919d1203b39f118a32870637dc5 Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Mon, 29 Apr 2024 13:10:01 +0200 Subject: [PATCH 6/7] ci: Check for unused import --- scripts/periphery.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/periphery.sh b/scripts/periphery.sh index 19c1b3965..0e97d5603 100755 --- a/scripts/periphery.sh +++ b/scripts/periphery.sh @@ -15,9 +15,9 @@ fi # Perform the periphery scan and handle directory removal based on argument if "$full_dir"; then - detailedOutput=$(periphery scan --quiet) + detailedOutput=$(periphery scan --quiet --enable-unused-import-analysis) else - detailedOutput=$(periphery scan --quiet | sed "s|$(pwd)/||g") + detailedOutput=$(periphery scan --quiet --enable-unused-import-analysis | sed "s|$(pwd)/||g") fi unusedCount=$(wc -l <<< "$detailedOutput" | tr -d '[:space:]') From b95a3c34d00788e9a5eceeffeed2d51666b935f7 Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Tue, 30 Apr 2024 10:34:01 +0200 Subject: [PATCH 7/7] fix: Avoid useless bool in script --- scripts/periphery.sh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/scripts/periphery.sh b/scripts/periphery.sh index 0e97d5603..97c6a99d6 100755 --- a/scripts/periphery.sh +++ b/scripts/periphery.sh @@ -6,15 +6,8 @@ tuist install tuist generate -n -# Check if the "--full-dir" argument is provided -if [[ "$1" == "--full-dir" ]]; then - full_dir=true -else - full_dir=false -fi - # Perform the periphery scan and handle directory removal based on argument -if "$full_dir"; then +if [[ "$1" == "--full-dir" ]]; then detailedOutput=$(periphery scan --quiet --enable-unused-import-analysis) else detailedOutput=$(periphery scan --quiet --enable-unused-import-analysis | sed "s|$(pwd)/||g")