Skip to content

ci: upload Codecov coverage from fork and Dependabot PRs - #252

Merged
dhalperi merged 1 commit into
masterfrom
ci-codecov-fork-pr-coverage
Jun 9, 2026
Merged

ci: upload Codecov coverage from fork and Dependabot PRs#252
dhalperi merged 1 commit into
masterfrom
ci-codecov-fork-pr-coverage

Conversation

@dhalperi

@dhalperi dhalperi commented Jun 9, 2026

Copy link
Copy Markdown
Member

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 (runs in base-repo context, so the token is available). Each checkout fetches the PR head sha and the upload passes override_commit/override_pr so coverage reflects and is attributed to the PR's code.
  • Guard the upload to PR events or pushes to master; Dependabot branch pushes lack the token.
  • Upload from every matrix version under a per-version flag (python-3.10python-3.14); Codecov merges all uploads for a commit. Add codecov.yml with after_n_builds so 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 Reviewable

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
dhalperi force-pushed the ci-codecov-fork-pr-coverage branch from 1df06a7 to 4017176 Compare June 9, 2026 03:21

@dhalperi dhalperi left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhalperi reviewed 2 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved.

@dhalperi
dhalperi merged commit 8f824fd into master Jun 9, 2026
8 checks passed
@dhalperi
dhalperi deleted the ci-codecov-fork-pr-coverage branch June 9, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant