Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Detect unused code with Periphery #1401

Merged
merged 7 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/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
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
33 changes: 33 additions & 0 deletions scripts/periphery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

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

tuist install
tuist generate -n
PhilippeWeidmann marked this conversation as resolved.
Show resolved Hide resolved


# 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
PhilippeWeidmann marked this conversation as resolved.
Show resolved Hide resolved
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
Loading