From 5b3dbc182f209db06e54f3b4a5f6a9fe023c6fd5 Mon Sep 17 00:00:00 2001 From: Paullo9 Date: Fri, 6 Nov 2026 14:42:50 +0100 Subject: [PATCH] ci: warn on new unused code in pull requests (Periphery baseline) The Periphery workflow gains a pull-request job that scans as the weekly job does, without the findings .periphery-baseline.json records (triaged and kept in the dead-code pass) and without Codable properties. A finding that is left is new and is annotated on the PR as a warning; the job stays green. The weekly scan is unchanged. Done: the warning-only check and its baseline. Next: make it a required check once it has stayed quiet for two weeks. Co-Authored-By: Claude --- .github/workflows/periphery.yml | 35 ++++++++++++++++++++++++++++++--- .periphery-baseline.json | 1 + 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 .periphery-baseline.json diff --git a/.github/workflows/periphery.yml b/.github/workflows/periphery.yml index 8ce31d4..ca121d6 100644 --- a/.github/workflows/periphery.yml +++ b/.github/workflows/periphery.yml @@ -1,12 +1,20 @@ -# Weekly unused-code scan (Periphery). A copy of the suite's template; edit it there. -# Builds the package and its tests, scans with --retain-public (a kit's public API is used by the apps), and keeps one -# open issue, "Periphery weekly scan", up to date with the findings. Findings are for triage; nothing is deleted here. +# Unused-code scan (Periphery). A copy of the suite's template; edit it there. +# Weekly: builds the package and its tests, scans with --retain-public (a kit's public API is used by the apps), and keeps +# one open issue, "Periphery weekly scan", up to date with the findings. Findings are for triage; nothing is deleted here. +# On a pull request that touches Swift: the same scan without the findings .periphery-baseline.json records (triaged and +# kept) and without Codable properties (test fixtures). A finding that is left is new: it is annotated on the PR as a +# warning and the job stays green. Delete the code or, for a false positive, write the baseline again in the same PR: +# swift build --build-system native --build-tests +# periphery scan --retain-public --retain-codable-properties --skip-build \ +# --index-store-path .build/debug/index/store --write-baseline .periphery-baseline.json name: Periphery on: schedule: - cron: "17 3 * * 0" workflow_dispatch: + pull_request: + paths: ["**.swift", ".periphery-baseline.json", ".github/workflows/periphery.yml"] permissions: contents: read @@ -14,6 +22,7 @@ permissions: jobs: scan: + if: github.event_name != 'pull_request' runs-on: macos-26 timeout-minutes: 60 steps: @@ -43,3 +52,23 @@ jobs: cat periphery.csv n=$(gh issue list --state open --search "in:title \"$title\"" --json number,title -q ".[] | select(.title == \"$title\") | .number" | head -1) if [ -n "$n" ]; then gh issue edit "$n" --body-file body.md; else gh issue create --title "$title" --body-file body.md; fi + + new-findings: + name: New unused code (warning only) + if: github.event_name == 'pull_request' + runs-on: macos-26 + timeout-minutes: 30 + permissions: + contents: read + steps: + - uses: actions/checkout@v7 + - name: Install Periphery + run: brew install periphery && periphery version + - name: Build with the index store + run: swift build --build-system native --build-tests + - name: Scan against the baseline + run: | + periphery scan --retain-public --retain-codable-properties --skip-build --index-store-path .build/debug/index/store \ + --baseline .periphery-baseline.json --format github-actions --relative-results | tee periphery.txt + count=$(grep -c '^::warning' periphery.txt || true) + echo "Periphery: ${count} new finding(s) against .periphery-baseline.json" >> "$GITHUB_STEP_SUMMARY" diff --git a/.periphery-baseline.json b/.periphery-baseline.json new file mode 100644 index 0000000..6c974a0 --- /dev/null +++ b/.periphery-baseline.json @@ -0,0 +1 @@ +{"v1":{"usrs":["s:20DiffractoOrientation16ACOMMetalContext33_E5198D0243076D13198CC392F70B7B9DLLC6ParamsV6radials6UInt32Vvp","s:20DiffractoOrientation16ACOMMetalContext33_E5198D0243076D13198CC392F70B7B9DLLC6ParamsV9azimuthals6UInt32Vvp","s:20DiffractoOrientation16ACOMMetalContext33_E5198D0243076D13198CC392F70B7B9DLLC6ParamsV9positionss6UInt32Vvp","s:20DiffractoOrientation16ACOMMetalContext33_E5198D0243076D13198CC392F70B7B9DLLC6ParamsV9templatess6UInt32Vvp","s:20DiffractoOrientation18PhaseVectorMatcherO11SendableBox33_3E50C60435D1B86CCF6F1F01DB5A19F5LLV5valueSpyAA0cD6ResultVGvp","s:23DiffractoKitParityTests04PinsD0V12CheckFailureV7messageSSvp"]}} \ No newline at end of file