Skip to content

feat(ci): teach [GitHubActions] about CheckoutRef so regen preserves the ref pin#175

Merged
ChrisonSimtian merged 1 commit into
mainfrom
feature/110-checkout-ref-attribute
May 25, 2026
Merged

feat(ci): teach [GitHubActions] about CheckoutRef so regen preserves the ref pin#175
ChrisonSimtian merged 1 commit into
mainfrom
feature/110-checkout-ref-attribute

Conversation

@ChrisonSimtian

Copy link
Copy Markdown
Collaborator

Summary

Fixes the annoying GenerateTools whack-a-mole on ubuntu-latest.yml: the manual ref: \${{ github.head_ref }} patch that keeps HEAD attached on PR builds is now first-class config on the [GitHubActions] attribute, so every subsequent regen re-emits it automatically.

Background

The ubuntu-latest PR workflow needs actions/checkout configured with ref: \${{ github.head_ref }} because:

  • GitHubTasksTest.GitHubRepositoryFromLocalDirectoryTest reads .git/HEAD via GitRepository.FromLocalDirectory.
  • On PR builds without the ref: pin, actions/checkout lands on a detached merge SHA, so HEAD has no branch → repository.Branch is null → test fails.

PR #172's GenerateTools run dropped the manual patch and CI went red. This PR makes the patch survive regenerations.

Changes

File Change
Fallout.Common/CI/GitHubActions/Configuration/GitHubActionsCheckoutStep.cs New Ref property + emits ref: <value> in the YAML when set.
Fallout.Common/CI/GitHubActions/GitHubActionsAttribute.cs New CheckoutRef setter forwards to the step.
build/Build.CI.GitHubActions.cs [GitHubActions(\"ubuntu-latest\", ..., CheckoutRef = \"\${{ github.head_ref }}\")]. macOS and Windows stay unchanged (they run on push-to-main, HEAD already attached).
.github/workflows/ubuntu-latest.yml Regenerated from the new attribute — same ref: line, no hand-written comment needed.

Test plan

  • Regen via dotnet run --project build/_build.csproj -- GenerateBuildServerConfigurations produces the expected ref: line.
  • dotnet test fallout.slnx — 425/425 pass.
  • CI ubuntu-latest green (validates the patch still works through the regen path).

🤖 Generated with Claude Code

…the ref pin

The ubuntu-latest workflow YAML carried a manual ref:github.head_ref patch
that keeps HEAD attached on PR-triggered builds. Without it,
GitHubTasksTest.GitHubRepositoryFromLocalDirectoryTest fails because
GitRepository.FromLocalDirectory can't resolve a branch from a detached merge SHA
(seen on PR #172 when GenerateTools clobbered the patch and CI went red).

Fix: surface the actions/checkout 'ref' input as first-class config on
GitHubActionsCheckoutStep + a CheckoutRef setter on [GitHubActions]. The
ubuntu-latest attribute in Build.CI.GitHubActions.cs now sets
CheckoutRef = "${{ github.head_ref }}", so subsequent GenerateTools runs
re-emit the patch automatically instead of dropping it.

macos-latest and windows-latest are unchanged — they run on push-to-main where
HEAD is already attached on the requested commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ChrisonSimtian
ChrisonSimtian merged commit 03d69b8 into main May 25, 2026
1 check passed
@ChrisonSimtian
ChrisonSimtian deleted the feature/110-checkout-ref-attribute branch May 25, 2026 08:08
ChrisonSimtian added a commit that referenced this pull request May 27, 2026
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>
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