Repository navigation
docs: upload coverage when CI only tests the modules that changed - #2824
heliocodacy wants to merge 1 commit into
Conversation
Codacy needs coverage data for all tested files on every commit, so monorepos whose CI only tests changed modules end up with incomplete coverage. Document a workaround on GitHub Actions: store each module's report as an artifact, reuse the most recent report for unchanged modules, and upload every report with --partial followed by final. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Overall readability score: 54.56 (🔴 -0.09)
View detailed metrics🟢 - Shows an increase in readability
Averages:
View metric targets
|
Up to standards ✅🟢 Issues
|
There was a problem hiding this comment.
Pull Request Overview
The documented artifact-selection workflow can reuse an older coverage report when overlapping runs complete out of order, producing incorrect aggregate coverage. This is a high-severity correctness issue that should be addressed before merging.
The workflow also has lower-severity operational gaps: artifact lookup is not paginated, pull-request change detection may lack required token permissions, and fork-based pull requests cannot access the upload token. The documented limitations should cover the fork case or provide a trusted upload path.
Test suggestions
- Fetch the current workflow's artifact when available and otherwise select the newest non-expired artifact from the default branch.
- Fail clearly when no artifact exists for a module.
- Run tests only for changed modules while always uploading coverage for every module.
- Upload reports as partial submissions and send the final notification after all reports are uploaded.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Fetch the current workflow's artifact when available and otherwise select the newest non-expired artifact from the default branch.
2. Fail clearly when no artifact exists for a module.
3. Run tests only for changed modules while always uploading coverage for every module.
4. Upload reports as partial submissions and send the final notification after all reports are uploaded.
Make this review better
TIP Add a ticket key to the branch or title so the reviewer can check the PR against it. Or tell us which ticket tracker you use here.
TIP How was this review? Give us feedback
| + ([$all[] | ||
| | select(.workflow_run.head_branch == $branch) | ||
| | select(.workflow_run.head_repository_id == .workflow_run.repository_id)] | ||
| | sort_by(.created_at) | reverse) |
There was a problem hiding this comment.
🔴 HIGH RISK
If an older default-branch run finishes after a newer one, subsequent commits reuse the older commit's report because it has the later creation time. Consider selecting reports by commit ancestry and handling runs whose required predecessor reports are still pending.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | ||
| CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Pull requests from forks cannot authenticate the coverage upload because CODACY_PROJECT_TOKEN is unavailable. Consider documenting this limitation or using a separate trusted workflow to upload fork coverage without executing untrusted code with the secret.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| gateway: ${{ steps.filter.outputs.gateway }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: dorny/paths-filter@v3 |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Pull-request runs fail to detect changes when the repository's default token permissions don't include pull-request access. Consider granting pull-requests: read and contents: read to this job.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| # Prefer the report from the current run. Otherwise, use the most recent | ||
| # report from the default branch of this repository. | ||
| artifact_id=$( | ||
| gh api "repos/$GITHUB_REPOSITORY/actions/artifacts?name=$artifact_name&per_page=100" | |
There was a problem hiding this comment.
🟡 MEDIUM RISK
If 100 newer pull-request artifacts exist, this lookup misses an unexpired default-branch report and fails the upload. Consider paginating the artifact listing before selecting a report.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
Codacy needs coverage data for all tested files on every commit and doesn't reuse coverage from previous commits. Monorepos whose CI only tests the modules a commit changed therefore end up with incomplete coverage and unexpected coverage changes. Codacy doesn't support this natively yet, so this PR documents a workaround.
Adds the section Uploading coverage when you only test the modules that changed (
#changed-modules) to Uploading coverage in advanced scenarios, after the section on uploading multiple reports. The page description already mentions monorepos, but the page had no monorepo guidance. The section covers:--partial, then sendfinalNotes for reviewers:
{% raw %}, like other pages that show GitHub Actions expressions, so the macros plugin doesn't render${{ }}.GitHubActionProvider, which reads the pull request head SHA. GitHub Actions is missing from the platform list in Troubleshooting Codacy Coverage Reporter issues. That's out of scope for this PR.Checks:
mkdocs build --strictpasses locally. Vale wasn't run locally, so CI will be its first run.👀 Live preview
Pending the branch preview deployment:
coverage-reporter/uploading-coverage-in-advanced-scenarios/#changed-modules🚧 To do
🤖 Generated with Claude Code