ci: upload Codecov coverage from fork and Dependabot PRs - #252
Merged
Conversation
Coverage upload failed on fork and Dependabot PRs because GitHub withholds
secrets from their pull_request runs, leaving CODECOV_TOKEN empty and the
upload rejected ("Token required because branch is protected").
Switch the trigger to pull_request_target, which runs in the base-repo
context where the token is available. Each checkout fetches the PR head sha
so coverage reflects the PR's code, and the upload passes override_commit
/override_pr to attribute coverage to the PR head. Guard the upload to PR
events or pushes to master, since Dependabot branch pushes lack the token.
This exposes the upload-only token to PR code, which is acceptable here.
Also upload from every matrix version, each under a per-version flag
(python-3.10 ... python-3.14); Codecov merges all uploads for a commit. Add
codecov.yml with after_n_builds so the report is not finalized from a
partial set of uploads.
----
Prompt:
```
Debug #251 - why does the
codecov action fail and what do I have to do to fix it?
```
Follow-up: clarified to provide accurate coverage on any external PR (not
just avoid failing), with CODECOV_TOKEN exposure acceptable; and to upload
from all matrix versions rather than one.
dhalperi
force-pushed
the
ci-codecov-fork-pr-coverage
branch
from
June 9, 2026 03:21
1df06a7 to
4017176
Compare
dhalperi
commented
Jun 9, 2026
dhalperi
left a comment
Member
Author
There was a problem hiding this comment.
@dhalperi reviewed 2 files and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved.
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.
Coverage upload failed on fork and Dependabot PRs because GitHub withholds secrets from their
pull_requestruns, leavingCODECOV_TOKENempty and the upload rejected ("Token required because branch is protected").pull_request_target(runs in base-repo context, so the token is available). Each checkout fetches the PR head sha and the upload passesoverride_commit/override_prso coverage reflects and is attributed to the PR's code.master; Dependabot branch pushes lack the token.python-3.10…python-3.14); Codecov merges all uploads for a commit. Addcodecov.ymlwithafter_n_buildsso the report isn't finalized from a partial set.This exposes the upload-only token to PR code, which is acceptable here.
Note: the new trigger is evaluated from
master, so it takes effect on the next PR after merge, not on this one.This change is