Skip to content

CI check for dead code #4

CI check for dead code

CI check for dead code #4

Workflow file for this run

name: Dead Code Detection
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
paths:
- '**/*.swift'
jobs:
dead-code-check:
runs-on: macos-13
permissions:
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Periphery
run: brew install peripheryapp/periphery/periphery
- name: Build project and run Periphery scan
id: periphery-scan
run: |
# Run Periphery scan with the configuration file
periphery scan --config .periphery.yml 2>&1 | sed -E 's#.*/##; s/:[0-9]+:[0-9]+:/: /' | grep 'is unused' | sort > periphery_report_feature_formatted_sorted.txt
- name: Compare Periphery output with master baseline
id: compare-dead-code
run: |
git fetch origin master:master
git checkout master
periphery scan --config .periphery.yml 2>&1 | sed -E 's#.*/##; s/:[0-9]+:[0-9]+:/: /' | grep 'is unused' | sort > periphery_report_master_formatted_sorted.txt
# Compare the formatted reports
diff_output=$(comm -13 periphery_report_master_formatted_sorted.txt periphery_report_feature_formatted_sorted.txt)
# If there is a difference, output it
if [ -n "$diff_output" ]; then
echo "diff<<EOF" >> $GITHUB_ENV
echo "$diff_output" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
fi
- uses: peter-evans/find-comment@v3
id: find_comment
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: '🚨 New dead code detected'
- uses: peter-evans/create-or-update-comment@v3
id: create_update_comment
if: env.diff != ''
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
🚨 New dead code detected in this PR:
```diff
${{ env.diff }}
```
Please remove the dead code before merging.
If this is intentional, you can bypass this check by adding the label `skip dead code check` to this PR.
ℹ️ If this comment appears to be left in error, make sure your branch is up-to-date with `master`.
edit-mode: replace
comment-id: ${{ steps.find_comment.outputs.comment-id }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Fail if not acknowledged
if: env.diff != '' && !contains(github.event.pull_request.labels.*.name, 'skip dead code check')
run: exit 1