Fix CI checkout and coverage upload for fork PRs#737
Merged
Conversation
The `build-and-test` checkout pinned `ref: ${{ github.head_ref || github.ref }}`
without a matching `repository`, so for cross-repository (fork) PRs Actions
looked for the head branch in the base repo and failed at checkout in ~7s with
"a branch or tag with the name '<head-branch>' could not be found" — before any
build or test ran. This affected all external/fork contributions (e.g. #735).
- Checkout: resolve `repository` and `ref` from the PR head when present
(`github.event.pull_request.head.*`), falling back to `github.repository` /
`github.ref` for push builds. The `ref` uses the head branch *name* (not the
head SHA) so HEAD stays attached to a branch — the KMMBridge plugin runs
`git pull --tags`, which fails on a detached HEAD ("you are not currently on a
branch"). Fork PRs now check out the contributor's head branch; same-repo PRs
and pushes to main are unchanged.
- Codecov: skip the upload on fork PRs, where `CODECOV_TOKEN` is unavailable and
`fail_ci_if_error: true` would otherwise fail the job. Coverage is still
uploaded and enforced for same-repo PRs and pushes to main.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
e8cae98 to
50a7416
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #737 +/- ##
=======================================
Coverage 80.17% 80.17%
=======================================
Files 42 42
Lines 928 928
Branches 177 177
=======================================
Hits 744 744
Misses 110 110
Partials 74 74 🚀 New features to boost your workflow:
|
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
CI fails at the Checkout step (~7s, before any build/test) for fork PRs. Example: #735 (run) died with:
The
build-and-testcheckout pinsref: ${{ github.head_ref || github.ref }}but never setsrepository, so for a cross-repository (fork) PRactions/checkoutlooks for the head branch in the base repo (MobileNativeFoundation/Store), where it doesn't exist — the branch lives in the contributor's fork. This is a latent bug introduced in #673; it never surfaced because every PR since has come from a same-repo branch.A second, downstream blocker: the Codecov step uses
secrets.CODECOV_TOKEN, which GitHub does not expose to fork PRs, combined withfail_ci_if_error: true— so even after fixing checkout, fork PRs would fail at coverage upload.Fix
repositoryandreffrom the PR head when present (github.event.pull_request.head.repo.full_name/head.sha), falling back togithub.repository/github.reffor push builds. Fork PRs now check out the contributor's head commit; same-repo PRs and pushes tomainare unchanged (still build the head commit, as before — not the merge ref).main.Notes / review call-outs
pull_requesttrigger (notpull_request_target), so fork builds run with a read-onlyGITHUB_TOKENand no secrets;persist-credentials: falseis retained. Building untrusted fork code underpull_requestis the standard, safe configuration.fail_ci_if_error: falseon that step instead of theif:guard — happy to switch.main; Fix RealMutableStore write-queue data race (inverted lock polarity) #735 will pass after it rebases on top of this (forks run the base branch's workflow definition forpull_request).🤖 Generated with Claude Code