77 description : ' Branch to release from (e.g., main, develop, hotfix/xyz, v1.2)'
88 type : string
99 required : true
10- is_prerelease :
11- type : boolean
12- required : true
13- default : false
14- is_draft :
15- type : boolean
16- required : true
17- default : false
1810 secrets :
1911 GH_TOKEN :
2012 required : true
@@ -28,24 +20,13 @@ jobs:
2820 create-release :
2921 runs-on : ubuntu-latest
3022 steps :
31- # Fail if trying to cut a prerelease from main
32- - name : Guard no prerelease from main
33- if : ${{ inputs.is_prerelease && inputs.target_branch == 'main' }}
34- run : |
35- echo "❌ Prereleases must not be cut from main. Use develop or hotfix/*."
36- exit 1
37-
38- # Fail if trying to cut a stable from develop or hotfix/*
39- - name : Guard stable not from develop/hotfix
40- if : ${{ !inputs.is_prerelease && (startsWith(inputs.target_branch, 'develop') || startsWith(inputs.target_branch, 'hotfix/')) }}
41- run : |
42- echo "❌ Stable releases should come from main or vX.Y servicing branches, not develop/hotfix/*."
43- exit 1
44-
4523 - name : Verify target branch exists on origin
4624 run : |
47- if ! git ls-remote --exit-code --heads origin "${{ inputs.target_branch }}" >/dev/null; then
48- echo "❌ Branch not found on origin: ${{ inputs.target_branch }}"
25+ set -e
26+ REPO_URL="https://github.com/${{ github.repository }}.git"
27+ BR="${{ inputs.target_branch }}"
28+ if ! git ls-remote --exit-code --heads "$REPO_URL" "$BR" >/dev/null; then
29+ echo "❌ Branch not found on origin: $BR"
4930 exit 1
5031 fi
5132
@@ -59,44 +40,40 @@ jobs:
5940 id : nbgv
6041 uses : dotnet/nbgv@v0.4.2
6142 with :
62- toolVersion : 3.8.38-alpha # keep behavior pinned
63- setAllVars : false
43+ toolVersion : 3.8.38-alpha
6444
65- - name : Sanity-check - requested prerelease vs computed version
45+ - name : Guard - block prerelease from main; block stable from develop/hotfix/*
6646 run : |
6747 PRE="${{ steps.nbgv.outputs.PrereleaseVersion }}"
68- if [[ "${{ inputs.is_prerelease }}" == "true" && -z "$PRE" ]]; then
69- echo "❌ Requested prerelease, but NBGV computed a STABLE version."
48+ BR="${{ inputs.target_branch }}"
49+ if [[ -n "$PRE" && "$BR" == "main" ]]; then
50+ echo "❌ Computed PRERELEASE on 'main'. Cut prereleases from develop or hotfix/*."
7051 exit 1
7152 fi
72- if [[ "${{ inputs.is_prerelease }}" == "false" && -n "$PRE" ]]; then
73- echo "❌ Requested STABLE, but NBGV computed a PRERELEASE ($PRE) ."
53+ if [[ -z "$PRE" && ( "$BR" == "develop" || "$BR" =~ ^hotfix/ ) ]]; then
54+ echo "❌ Computed STABLE on '$BR'. Stable releases should come from main or vX.Y ."
7455 exit 1
7556 fi
7657
7758 - name : Tag current commit with NBGV
7859 run : |
7960 git config user.name "${{ github.actor }}"
8061 git config user.email "${{ github.actor }}@users.noreply.github.com"
81- # Creates annotated tag v{NuGetPackageVersion} at HEAD
8262 nbgv tag || echo "Tag may already exist locally."
8363 git push origin "v${{ steps.nbgv.outputs.NuGetPackageVersion }}" || echo "Tag already exists on remote."
8464
8565 - name : Create GitHub Release
8666 env :
8767 GH_TOKEN : ${{ secrets.GH_TOKEN }}
8868 run : |
69+ TAG="v${{ steps.nbgv.outputs.NuGetPackageVersion }}"
70+ PRE="${{ steps.nbgv.outputs.PrereleaseVersion }}"
71+ BR="${{ inputs.target_branch }}"
8972 FLAGS=()
90- [[ "${{ inputs.is_draft }}" == "true" ]] && FLAGS+=(--draft)
91- [[ "${{ inputs.is_prerelease }}" == "true" ]] && FLAGS+=(--prerelease)
92-
93- # Mark latest for stable releases from main or servicing branches vX.Y
94- if [[ "${{ inputs.target_branch }}" == "main" || "${{ inputs.target_branch }}" =~ ^v[0-9]+\.[0-9]+$ ]]; then
95- if [[ "${{ inputs.is_prerelease }}" != "true" ]]; then
96- FLAGS+=(--latest)
97- fi
73+ [[ -n "$PRE" ]] || FLAGS+=(--latest) # latest only for stable
74+ # Only mark latest for stable from main or servicing branches vX.Y
75+ if [[ -n "$PRE" || ( "$BR" != "main" && ! "$BR" =~ ^v[0-9]+\.[0-9]+$ ) ]]; then
76+ FLAGS=("${FLAGS[@]/--latest}") # strip latest if conditions not met
9877 fi
99-
100- TAG="v${{ steps.nbgv.outputs.NuGetPackageVersion }}"
101- echo "Creating release ${TAG} from '${{ inputs.target_branch }}'"
78+ echo "Creating release ${TAG} from '${BR}'"
10279 gh release create "${TAG}" --title "${TAG}" --generate-notes "${FLAGS[@]}"
0 commit comments