Skip to content

Commit

Permalink
ci: Detect unused code with Periphery (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeWeidmann authored Apr 30, 2024
2 parents 09b3664 + b95a3c3 commit 3aba2ba
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/periphery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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/[email protected]
with:
access_token: ${{ github.token }}
- uses: jdx/mise-action@v2
with:
cache: false
- 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
<details>
<summary>Expand</summary>
```
${{ steps.periphery.outputs.detailed_output }}
```
</details>
2 changes: 2 additions & 0 deletions .github/workflows/uitests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .mise.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[tools]
tuist = '4.9.0'
periphery = '2.18.0'
swiftformat = '0.53.7'
swiftlint = '0.54.0'
swiftlint = '0.54.0'
19 changes: 19 additions & 0 deletions .periphery.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions scripts/periphery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

eval "$($HOME/.local/bin/mise activate -C $SRCROOT bash --shims)"

tuist install
tuist generate -n


# Perform the periphery scan and handle directory removal based on argument
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")
fi

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<<EOF' >> $GITHUB_OUTPUT
echo "$detailedOutput" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT

echo "unused_count=$unusedCount" >> $GITHUB_OUTPUT

0 comments on commit 3aba2ba

Please sign in to comment.