-
Notifications
You must be signed in to change notification settings - Fork 0
A10 - Swift Duplication Detection #1085
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: Swift Duplication Guard | ||
|
|
||
| on: | ||
| workflow_dispatch: {} | ||
| pull_request: | ||
| branches: | ||
| - "**" | ||
| paths: | ||
| - 'Sources/**/*.swift' | ||
| - 'Tests/**/*.swift' | ||
| - 'FoundationUI/**/*.swift' | ||
| - 'Examples/**/*.swift' | ||
| - 'scripts/run_swift_duplication_check.sh' | ||
| - '.github/workflows/swift-duplication.yml' | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'Sources/**/*.swift' | ||
| - 'Tests/**/*.swift' | ||
| - 'FoundationUI/**/*.swift' | ||
| - 'Examples/**/*.swift' | ||
| - 'scripts/run_swift_duplication_check.sh' | ||
| - '.github/workflows/swift-duplication.yml' | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| swift-duplication: | ||
| name: Swift Duplication Guard | ||
| runs-on: ubuntu-22.04 | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
|
|
||
| - name: Disable npm funding messages | ||
| run: npm config set fund false | ||
|
|
||
| - name: Run Swift duplication check | ||
| run: | | ||
| set -eo pipefail | ||
| mkdir -p artifacts | ||
| scripts/run_swift_duplication_check.sh | ||
|
|
||
| - name: Upload duplication report | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: swift-duplication-report | ||
| path: artifacts/swift-duplication-report.txt | ||
| retention-days: 30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # A10 — Swift Duplication Detection | ||
|
|
||
| **Status**: COMPLETED | ||
|
|
||
| ## 🎯 Objective | ||
| Ship the Swift duplication guard workflow so CI fails whenever duplicated Swift code exceeds 1% or any single clone surpasses 45 lines, keeping the codebase maintainable alongside the existing lint, format, and coverage gates. | ||
|
|
||
| ## 🧩 Context | ||
| - Phase A automation follow-up after completing A7 (SwiftLint guard) and A8 (coverage gate); execution workplan lists A10 as the next unblocked infrastructure task. | ||
| - PRD `DOCS/AI/github-workflows/02_swift_duplication_guard/prd.md` defines the workflow scope, thresholds, and documentation touch points. | ||
| - Current CI lacks duplication enforcement, so regressions risk slipping through while other gates are green. | ||
| - Requires only existing CI capabilities (Node 20 already available); no blockers recorded in `next_tasks.md` or workplan. | ||
|
|
||
| ## ✅ Success Criteria | ||
| - `.github/workflows/swift-duplication.yml` runs on `push` to `main` and `pull_request`, executing `scripts/run_swift_duplication_check.sh`. | ||
| - Workflow provisions Node 20, runs `npx jscpd@3.5.10` against Swift sources, and fails when duplicated percentage exceeds 1.0% or any block is ≥45 lines. | ||
| - Console report saved to `artifacts/swift-duplication-report.txt` (or similar) and uploaded via `actions/upload-artifact` for each CI run. | ||
| - Pre-push integration implemented: the pre-push hook invokes the duplication check via the wrapper and stores its report under `Documentation/Quality/`, so developers can check duplication before pushing. | ||
| - Documentation updated (`todo.md`, Execution Workplan row A10, and refs inside the PRD) to indicate both the CI gate and pre-push hook are live with remediation guidance. | ||
|
|
||
| ## 📦 Delivery Notes (2025-12-18) | ||
| - Added `scripts/run_swift_duplication_check.sh` wrapper for `npx jscpd@3.5.10` with the Phase A thresholds (≤1% overall, <45-line clones) and ignores for generated artifacts/Derived/.build/TestResults. Console output is mirrored to `artifacts/swift-duplication-report.txt`, scoped to Swift files only. | ||
| - Introduced `.github/workflows/swift-duplication.yml` that provisions Node 20, runs the wrapper on PRs and pushes to `main`, and uploads the `swift-duplication-report` artifact with 30-day retention. | ||
| - Updated documentation touchpoints (`todo.md`, `DOCS/AI/ISOInspector_Execution_Guide/04_TODO_Workplan.md`, `DOCS/AI/github-workflows/02_swift_duplication_guard/prd.md`) with live-gate status and remediation guidance; pre-push hook now invokes the wrapper and stores reports under `Documentation/Quality/`. | ||
| - Deduplicated the shared `InMemoryRandomAccessReader` helper into `Sources/ISOInspectorKit/TestSupport/` to clear the last in-repo clone and keep test support centralized. | ||
|
|
||
| ## 🔧 Implementation Notes | ||
| - Add helper script `scripts/run_swift_duplication_check.sh` that wraps the exact `jscpd` invocation so developers can run it locally; ensure executable bit set and path used by CI workflow. | ||
| - `jscpd` flags per PRD: `--format swift --pattern "**/*.swift" --reporters console --min-tokens 120 --threshold 1 --max-lines 45 --ignore "**/Derived/**" "**/Documentation/**" "**/.build/**" "**/TestResults-*"` (adjust ignore list if needed for generated artifacts). | ||
| - Use `actions/setup-node@v4` with caching to reduce install time; rely on `npm config set fund false` to keep logs quiet if needed. | ||
| - Artifact upload should retain at least 30 days to match other CI logs; align naming with coverage/SARIF artifacts for consistency. | ||
| - Update `DOCS/INPROGRESS/next_tasks.md` to mark A10 as in progress and remove it from the queue of ready items. | ||
|
|
||
| ## 🧠 Source References | ||
| - [`ISOInspector_Master_PRD.md`](../AI/ISOViewer/ISOInspector_PRD_Full/ISOInspector_Master_PRD.md) | ||
| - [`04_TODO_Workplan.md`](../AI/ISOInspector_Execution_Guide/04_TODO_Workplan.md) | ||
| - [`ISOInspector_PRD_TODO.md`](../AI/ISOViewer/ISOInspector_PRD_TODO.md) | ||
| - [`DOCS/RULES`](../RULES) | ||
| - [`PRD: Swift Duplication Guard`](../AI/github-workflows/02_swift_duplication_guard/prd.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
DOCS/INPROGRESS/A8_Test_Coverage_Gate.md → ...lved_Tasks_Batch/A8_Test_Coverage_Gate.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.