From ec8f3a69b95548546a51e60606c98bb679ad9600 Mon Sep 17 00:00:00 2001 From: Jimmy Bogard Date: Mon, 26 Oct 2026 17:07:57 -0500 Subject: [PATCH 1/2] Fail the release when the tag is not on its release branch A tag created from the GitHub Releases UI can land on the default branch instead of the selected one, which is how v15.1.1 and v15.1.2 were built from 16.x code (#4620). Before building, verify the tagged commit is on release/.x when that branch exists, otherwise on main. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a344ec7da7..6776e3e163 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,24 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Verify tag is on its release branch + # A tag created from the GitHub Releases UI can land on the default branch instead of the selected one (#4620) + run: | + set -euo pipefail + major="${GITHUB_REF_NAME#v}" + major="${major%%.*}" + if git ls-remote --exit-code --heads origin "release/${major}.x" > /dev/null; then + branch="release/${major}.x" + else + branch="main" + fi + git fetch --no-tags origin "+refs/heads/${branch}:refs/remotes/origin/${branch}" + if ! git merge-base --is-ancestor "$GITHUB_SHA" "origin/${branch}"; then + echo "::error::Tag ${GITHUB_REF_NAME} (${GITHUB_SHA}) is not on ${branch}. Delete the tag and recreate it on ${branch}." + exit 1 + fi + echo "Tag ${GITHUB_REF_NAME} is on ${branch}" + shell: bash - name: Setup dotnet uses: actions/setup-dotnet@v4 with: From 06e094a0b0ead793b6906e2dfb68e0c12e643156 Mon Sep 17 00:00:00 2001 From: Jimmy Bogard Date: Mon, 26 Oct 2026 17:12:00 -0500 Subject: [PATCH 2/2] Only fall back to main when the release branch does not exist git ls-remote --exit-code returns 2 for no matching refs and 128 for a failed lookup. Treating any failure as "no release branch" could let a transient error pass a v15.* tag on main. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6776e3e163..0aecb4cc7c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,10 +25,16 @@ jobs: set -euo pipefail major="${GITHUB_REF_NAME#v}" major="${major%%.*}" - if git ls-remote --exit-code --heads origin "release/${major}.x" > /dev/null; then + status=0 + git ls-remote --exit-code --heads origin "release/${major}.x" > /dev/null || status=$? + # Exit code 2 means no matching branch; anything else is a failed lookup + if [ "$status" -eq 0 ]; then branch="release/${major}.x" - else + elif [ "$status" -eq 2 ]; then branch="main" + else + echo "::error::Could not look up release/${major}.x (git ls-remote exit code ${status})" + exit 1 fi git fetch --no-tags origin "+refs/heads/${branch}:refs/remotes/origin/${branch}" if ! git merge-base --is-ancestor "$GITHUB_SHA" "origin/${branch}"; then