Repository navigation
fix(ci): checkout PR head SHA so fork PRs resolve - #489
Merged
Merged
Conversation
The `validate` job failed for fork PRs because its checkout used `ref: github.head_ref`, which is the branch name on the head repo. For forks the base repo's GITHUB_TOKEN can't fetch refs/heads/<name> on the fork; the run died at the first step with: A branch or tag with the name '<branch>' could not be found Switch the ref to `github.event.pull_request.head.sha`, which resolves via `refs/pull/<N>/head` on the base repo. This works for fork and same-repo PRs alike. `workflow_dispatch` still honors its `inputs.branch` and falls back to `github.ref_name`. Also add `persist-credentials: false` so the token isn't written to `.git/config` after checkout (no later step reuses it). Fixes #486 (validate job only; pr-check ASCII + standards drift jobs already worked because they use the fork-aware default checkout from n3ary/actions).
ciotlosm
force-pushed
the
fix/pr-check-fork-checkout
branch
from
September 28, 2026 17:42
b592113 to
cca0c43
Compare
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.
Problem
The
validatejob in.github/workflows/pr-check.ymlfails on fork PRs at the very first step (Checkout PR branch) with:The shared
pr-checkreusable workflow fromn3ary/actions(ASCII-only check, Standards drift check) handles fork PRs correctly — it ran and passed on #486. Only the repo-localvalidatejob was affected.Root cause
The
validatejob's checkout used:github.head_refis the branch name on the head repo. For fork PRs that name lives on the fork (e.g.valeboth/app), not onn3ary/app. Withrepositorydefaulting to the base repo,actions/checkoutdoesgit fetch origin refs/heads/<name>and finds nothing —GITHUB_TOKENhas no access to fork branches by name.The shared pr-check avoids this by relying on
actions/checkout's default fork-aware checkout (no explicitref).Fix
Switch to
github.event.pull_request.head.sha. The PR commit SHA resolves via the magic refrefs/pull/<N>/headon the base repo, whichGITHUB_TOKENcan read. This works for fork and same-repo PRs alike.The
workflow_dispatchpath (manual rerun from the Actions UI) still honorsinputs.branchand falls back togithub.ref_name.Also added
persist-credentials: falseso the token isn't written to.git/configafter checkout — no subsequent step reuses it.Diff
- name: Checkout PR branch uses: actions/checkout@v7 with: - ref: ${{ inputs.branch || github.head_ref }} + # Use the PR head SHA, not github.head_ref. For fork PRs, the + # branch NAME lives on the head repo and refs/heads/<name> + # is unreachable from the base repo's GITHUB_TOKEN; head.sha + # resolves via refs/pull/<N>/head which IS accessible, and + # works for same-repo PRs too. workflow_dispatch falls back + # to the user-supplied input or the dispatch's ref name. + ref: >- + ${{ + inputs.branch + || (github.event_name == 'pull_request' && github.event.pull_request.head.sha) + || github.ref_name + }} fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} + # Don't persist the token to .git/config; no subsequent + # step reuses it. + persist-credentials: falseVerification
After merge, re-running the
validatejob on #486 should:pnpm check,pnpm test,pnpm buildagainst the PR head codeRefs: #486