Skip to content

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions