Skip to content

Prerelease fix (#215 GITHUB_REF override) is ineffective — GITHUB_REF is reserved; use IGNORE_GITHUB_REF #221

Closed

Description

@ptr727

Summary

The fix for #213 (PR #215) restores the develop leg's prerelease tag by overriding GITHUB_REF in the nbgv step env:. This does not work. GITHUB_REF is a GitHub-reserved variable that a step-level env: cannot reliably override — the runner re-injects the dispatch ref. NBGV's GitHub Actions cloud-build provider reads GITHUB_REF for BuildingRef, so on a publish dispatched from main the develop leg is still classified as the public ref and publishes a clean (stable) version.

Evidence (CI)

First real publish after #215 landed in a derived repo — the develop leg's nbgv step:

GITHUB_REF: refs/heads/develop      # the step-env override (as configured)
"BuildingRef": "refs/heads/main"    # NBGV still saw the dispatch ref
"PublicRelease": true
"SemVer2": "1.4.2"                   # clean, no -g suffix

The validate-release gate correctly blocked the publish (so no bad package shipped), but the develop prerelease leg never publishes.

Root cause

GITHUB_REF is reserved; overriding it via step env: is unsupported (GitHub: "Setting an environment variable with the GITHUB_ prefix may result in unexpected behavior"). NBGV reads it for BuildingRef:

// src/NerdBank.GitVersioning/CloudBuildServices/GitHubActions.cs
private static string BuildingRef => IgnoreGitHubRef ? null : Environment.GetEnvironmentVariable("GITHUB_REF");
private static bool IgnoreGitHubRef => string.Equals(Environment.GetEnvironmentVariable("IGNORE_GITHUB_REF"), "true", StringComparison.OrdinalIgnoreCase);

Fix

NBGV versions from the checked-out branch; its cloud provider only overrides that with GITHUB_REF. Each matrix leg already checks out its own branch (Switched to a new branch 'develop'). Set NBGV's own IGNORE_GITHUB_REF=true so it ignores the CI ref and uses the checked-out branch:

      - name: Run Nerdbank.GitVersioning tool step
        id: nbgv
        uses: dotnet/nbgv@master
        env:
          IGNORE_GITHUB_REF: true

Drop the branch input/threading added to get-version-task.yml and its callers for the (ineffective) GITHUB_REF override; the validate-release entry gate stays as the backstop.

Verified (CI probe, real dotnet/nbgv action)

checkout IGNORE_GITHUB_REF PublicRelease SemVer2
develop true False 1.4.2-g14f645dfd9
main true True 1.4.3
main false False 1.4.3-g… (reproduces the bug)

Supersedes #215. Found in a derived repo's first real publish + a CI probe.

Activity

  1. added a commit that references this issue on Jun 27, 2026
    36f7eeb
  2. ptr727 commented on Jun 27, 2026

    @ptr727
    OwnerAuthor

    Fixed on develop via #222 (36f7eeb): NBGV IGNORE_GITHUB_REF (supersedes the ineffective #215 GITHUB_REF override; validate-release gate retained as backstop). Ships on the next develop → main release.

  3. ptr727 commented on Jun 27, 2026

    @ptr727
    OwnerAuthor

    Important refinement — IGNORE_GITHUB_REF=true alone is insufficient; it must be paired with re-adding the branch input and a git checkout -B <branch> step.

    Reason: with IGNORE_GITHUB_REF, NBGV versions from the checked-out git branch. build-nugetlibrary (and any caller pinning to a commit SHA) checks out a detached HEAD, where NBGV sees no branch and classifies every leg as prerelease — so the main leg builds a X.Y.Z-g<sha> package that mismatches its clean X.Y.Z release tag.

    Verified with the nbgv tool:

    state result
    detached at main SHA + IGNORE_GITHUB_REF PublicRelease=False, 1.4.3-gef05e9edc1 (wrong)
    detached + IGNORE_GITHUB_REF + git checkout -B main PublicRelease=True, 1.4.3 (correct)

    Complete fix

    get-version-task.yml: keep the branch input; after checkout, force a local branch so NBGV sees the logical branch from a detached SHA:

          - name: Checkout code step
            uses: actions/checkout@... 
            with:
              ref: ${{ inputs.ref }}
              fetch-depth: 0
    
          - name: Pin logical branch step
            if: ${{ inputs.branch != '' }}
            env:
              BRANCH: ${{ inputs.branch }}
            run: git checkout -B "$BRANCH"
    
          - name: Run Nerdbank.GitVersioning tool step
            id: nbgv
            uses: dotnet/nbgv@master
            env:
              IGNORE_GITHUB_REF: true

    Thread branch to both get-version callers (build-release-task and build-nugetlibrary-task).

    CI-verified (detached build-nugetlibrary path)

    leg built package
    main ptr727.LanguageTags.1.4.3.nupkg (clean)
    develop ptr727.LanguageTags.1.4.4-gf2560a8e4c.nupkg (prerelease)

    (The cleaner long-term alternative is to compute the version once and thread it into build-nugetlibrary rather than recomputing on a detached checkout — that removes the dual-get-version divergence entirely.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions