Skip to content

fix(ci): [GitHubActions] CheckoutRef now resolves cross-repo PRs#229

Merged
ChrisonSimtian merged 1 commit into
mainfrom
fix/checkout-cross-repo-pr-resolution
May 27, 2026
Merged

fix(ci): [GitHubActions] CheckoutRef now resolves cross-repo PRs#229
ChrisonSimtian merged 1 commit into
mainfrom
fix/checkout-cross-repo-pr-resolution

Conversation

@ChrisonSimtian

Copy link
Copy Markdown
Collaborator

Why

Regression introduced by #175. The `[GitHubActions]` generator emits:

```yaml

  • uses: actions/checkout@v6
    with:
    ref: ${{ github.head_ref }}
    ```

…without setting `repository:`. Checkout defaults to `${{ github.repository }}` (this repo) and tries to find the branch by name on `origin`. For PRs from a fork, the source branch only exists on the contributor's fork — checkout fails with:

```
fatal: A branch or tag with the name 'fix/...' could not be found
```

Dennis Doomen's PR #222 (cross-repo, from his fork) hits this on every CI run.

What this PR changes

`src/Fallout.Common/CI/GitHubActions/Configuration/GitHubActionsCheckoutStep.cs` — when `Ref` is set, the generator now also emits:

```yaml
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
```

The `||` fallback handles the three event shapes correctly:

Event Resolves to
Fork PR `/` — pulls the branch from the fork
Same-repo PR `` — same as today
Push `` (pull_request context is null → fallback)

Touch-ups:

  • Doc comments on `CheckoutRef` and `Ref` updated to describe the cross-repo behaviour.
  • New regression test case `checkout-ref` in `ConfigurationGenerationTest` locks the YAML shape. Verified snapshot committed.
  • `.github/workflows/ubuntu-latest.yml` regenerated by the build (`dotnet fallout --help` triggers the `[GitHubActions]` codegen as a side effect). `macos-latest` / `windows-latest` / `release.yml` unchanged — none set `CheckoutRef`.
  • CHANGELOG entry under `[Unreleased] — 11.0`.

Verification

  • `Fallout.Common.Tests` `ConfigurationGenerationTest`: 7/7 (was 6/6) passed locally.
  • Diff on `.github/workflows/ubuntu-latest.yml` is exactly the new `repository:` line. Three other auto-generated workflows untouched.

After this PR merges, #222 (Dennis's GitVersion-parse fix) will pick up the corrected workflow on its next CI run — a re-trigger or any new push to his branch.

Refs

Regression introduced by #175. The generated workflow emitted:

    - uses: actions/checkout@v6
      with:
        ref: ${{ github.head_ref }}

…but didn't set `repository:`. Checkout defaulted to
`${{ github.repository }}` (this repo) and tried to resolve
`fix/whatever` as a local branch — which fails for fork PRs because
the source branch only exists on the contributor's fork.

Symptom: cross-repo PRs (e.g. Dennis Doomen's #222 from his fork)
fail at the `Run actions/checkout@v6` step with:

    fatal: A branch or tag with the name 'fix/...' could not be found

#175's `CheckoutRef = "${{ github.head_ref }}"` was added so
GitVersion / GitRepository.FromLocalDirectory see the source branch
in `.git/HEAD` (otherwise checkout puts you on the merge ref in
detached-HEAD state). Goal correct; cross-repo coverage missed.

Fix:
  - GitHubActionsCheckoutStep.Write now emits a `repository:` line
    whenever `Ref` is non-empty:
        repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
    The `||` fallback covers push events (no pull_request context).
  - Doc comments on CheckoutRef + Ref updated.
  - New regression test case `checkout-ref` in ConfigurationGenerationTest
    locks the YAML shape. Verified snapshot committed alongside.
  - .github/workflows/ubuntu-latest.yml regenerated by the build.
    macos-latest / windows-latest / release.yml unchanged (none set
    CheckoutRef).
  - CHANGELOG.md entry under [Unreleased] — 11.0.

After this lands, Dennis's PR #222 will pick up the fix on the next
workflow run (any rerun, or a push to his branch).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ChrisonSimtian
ChrisonSimtian merged commit 1e60bf0 into main May 27, 2026
2 checks passed
@ChrisonSimtian
ChrisonSimtian deleted the fix/checkout-cross-repo-pr-resolution branch May 27, 2026 11:01
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