Repository navigation
ci: fix coverage comment on fork PRs, switch README to dynamic badge - #31
Merged
Merged
Conversation
The Test workflow ran as a single pull_request job that needed pull-requests:write to post the coverage comment and contents:write to push a README badge update back to the PR branch. Both fail on fork PRs: GITHUB_TOKEN is read-only and you can't push to a fork branch from the base repo's CI. Split into two workflows: - test.yml runs on pull_request with read-only perms, generates coverage.xml, and uploads it (plus the PR number) as an artifact. - coverage-comment.yml runs on workflow_run with pull-requests:write, downloads the artifact, and posts the comment on the PR. This runs in the base-repo context so it works for fork PRs without checking out untrusted code. Also drops the auto-push of a coverage badge into README.md from PR builds. That step pushed bot commits to contributor branches, risked CI loops, and could never work on forks anyway. If we want a coverage badge on main, that belongs in a separate push-to-main workflow or a dynamic Shields.io endpoint, not in PR CI.
Adds a Coverage Badge workflow that runs on push to main, generates a shields.io endpoint JSON from coverage.xml, and force-pushes it to a dedicated `badges` orphan branch. The README now references a shields.io endpoint URL that resolves through raw.githubusercontent.com, so the badge updates automatically on every merge to main with no commits to main itself. This replaces the previous static <img> tag in the README and removes the need for the deleted README auto-push step in PR CI. Note: the badge will appear broken until this branch lands on main and the Coverage Badge workflow runs for the first time, creating the `badges` branch and seeding coverage.json.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Testworkflow so it works for PRs from forks (which only get a read-onlyGITHUB_TOKEN).Coverage Commentworkflow that runs onworkflow_runand posts the coverage comment withpull-requests: writefrom the base-repo context.Coverage Badgeworkflow that runs on push tomain, generates a shields.io endpoint JSON, and publishes it to a dedicatedbadgesorphan branch. README now references that JSON so the badge updates dynamically on every merge tomain.Why
All three currently open PRs from external contributors (#22, #24, #30) fail the same way: the coverage-comment step calls the GitHub API with a read-only token, and the README auto-push step tries to push to a fork branch. Both are impossible from a
pull_request-triggered workflow on a fork.The fix is the canonical two-workflow pattern recommended by both
MishaKav/pytest-coverage-commentandpy-cov-action/python-coverage-comment-action:test.ymlruns onpull_request, has read-only perms, and only generates + uploads acoverage.xmlartifact (pluspr_number.txt).coverage-comment.ymlruns onworkflow_runafterTestcompletes. Becauseworkflow_runalways runs in the base-repo context, it has thepull-requests: writepermission it needs. It downloads the artifact and posts the comment.This is strictly safer than the
pull_request_targetalternative becausecoverage-comment.ymlnever checks out PR code, so a malicious fork cannot get its code executed with elevated permissions.Dynamic README badge
To replace the previous "auto-commit a static badge to every PR branch" hack:
coverage-badge.ymlruns on push tomain, generates a shields.io endpoint JSON with the percentage and a threshold-based color, and force-pushes it to abadgesorphan branch (single file, replaces previous on each run).<img>now points athttps://img.shields.io/endpoint?url=https://raw.githubusercontent.com/glassflow/glassgen/badges/coverage.json, which shields.io fetches on demand.Net effect: no more bot commits to
main, no more bot pushes to PR branches, and the badge stays current automatically.Test plan
Coverage Badgeworkflow runs againstmain, creates thebadgesbranch, and the README badge resolves to a real percentage.Notes
Coverage Badgerun completes (seconds, but worth knowing).test (3.11)failure observed on Array generator enhancements #22, [FEATURE] Added BigQuery Sink #24, Added Day , Month and Year Generators #30 is not fixed by this PR — that looks like a real test failure or deps issue worth a separate look. This PR only fixes the CI plumbing so the failure modes get reported cleanly.