Skip to content

ci: fall back to GITHUB_TOKEN for grcov install on fork PRs - #961

Merged
aterentic-ethernal merged 1 commit into
mainfrom
fix/grcov-token-fork-prs
Aug 3, 2026
Merged

aterentic-ethernal merged 1 commit into
mainfrom
fix/grcov-token-fork-prs

Conversation

@aterentic-ethernal

Copy link
Copy Markdown
Contributor

The cargo test job fails on every pull request opened from a fork, before the coverage report is generated. Tests themselves pass; the job dies at the Install grcov step with Input required and not supplied: github-token. This makes the fix a prerequisite for merging any external contribution.

The cause is that GitHub withholds repository secrets from workflows triggered by pull_request events originating in a fork. secrets.PAT_TOKEN therefore expands to an empty string, and because Actions drops empty inputs entirely, SierraSoftworks/setup-grcov sees its required github-token input as absent rather than blank.

How it works

  • secrets.PAT_TOKEN || secrets.GITHUB_TOKEN keeps the PAT on branch pushes and same-repo pull requests, where it is available and carries higher API rate limits.
  • On fork pull requests the expression falls through to GITHUB_TOKEN, which is minted per job rather than stored as a repository secret and so remains available.
  • GITHUB_TOKEN is forced read-only for fork pull requests. Downloading a grcov release asset needs only read access, so the reduced scope is sufficient.
  • No additional credential is exposed. GITHUB_TOKEN is already present in every job context; passing it as an action input does not widen what a workflow can reach.

Caveats

  • Withholding PAT_TOKEN from fork pull requests is a deliberate protection, not a misconfiguration. Routing around it with pull_request_target would run the base workflow with full secrets and is deliberately not done here.
  • arduino/setup-protoc reads the same secret via repo-token and is left unchanged. It treats the token as optional, so on fork pull requests it silently falls back to unauthenticated API calls and could hit rate limits under load. Worth a follow-up, but it is not currently failing.
  • The codecov/codecov-action upload step runs without a token on fork pull requests. Tokenless upload generally works for public repositories, so it is untouched here.
  • Open pull requests pick this up once their merge ref is recomputed against main; no rebase is needed. Re-running an existing failed run reuses the old commit and will not see the change, so a fresh run is required.

Secrets are withheld from workflows triggered by pull_request events
from forks, so secrets.PAT_TOKEN expands to an empty string. Actions
drops empty inputs, leaving setup-grcov without its required
github-token and failing the job before coverage runs.

GITHUB_TOKEN is minted per job and stays available on fork PRs, where
it is forced read-only. That is sufficient to download a grcov release
asset, so fork PRs no longer depend on a secret they cannot receive.

@brixial brixial left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@aterentic-ethernal
aterentic-ethernal merged commit 78aa2a0 into main Aug 3, 2026
4 checks passed
@aterentic-ethernal
aterentic-ethernal deleted the fix/grcov-token-fork-prs branch August 3, 2026 08:21
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.

2 participants