Skip to content

Commit 1e2b2ec

Browse files
Update create_new_release.yml
1 parent 587c8ff commit 1e2b2ec

1 file changed

Lines changed: 41 additions & 18 deletions

File tree

.github/workflows/create_new_release.yml

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Create Release
33
on:
44
workflow_call:
55
inputs:
6+
target_branch:
7+
description: 'Branch to release from (e.g., main, develop, hotfix/xyz, v1.2)'
8+
type: string
9+
required: true
610
is_prerelease:
711
type: boolean
812
required: true
@@ -20,49 +24,63 @@ permissions:
2024
pull-requests: write
2125
packages: write
2226

23-
env:
24-
ALLOW_PRERELEASE: ${{ startsWith(github.ref, 'refs/heads/develop') || startsWith(github.ref, 'refs/heads/hotfix/') }}
25-
2627
jobs:
2728
create-release:
2829
runs-on: ubuntu-latest
2930
steps:
30-
- name: Validate prerelease usage
31-
if: ${{ ( env.ALLOW_PRERELEASE == 'true' && inputs.is_prerelease == false ) || ( github.ref == 'refs/heads/main' && inputs.is_prerelease == true ) }}
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/')) }}
3241
run: |
33-
echo "Prereleases should not be triggered on main; use develop or hotfix/*."
42+
echo "❌ Stable releases should come from main or vX.Y servicing branches, not develop/hotfix/*."
3443
exit 1
3544
36-
- name: Checkout (full history for NBGV)
45+
- name: Verify target branch exists on origin
46+
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 }}"
49+
exit 1
50+
fi
51+
52+
- name: Checkout target branch (full history for NBGV)
3753
uses: actions/checkout@v4
3854
with:
39-
fetch-depth: 0 # required by nbgv
55+
fetch-depth: 0
56+
ref: ${{ inputs.target_branch }}
4057

4158
- name: Nerdbank.GitVersioning (install + outputs)
4259
id: nbgv
4360
uses: dotnet/nbgv@v0.4.2
4461
with:
45-
toolVersion: 3.8.38-alpha # pin to your current CLI
46-
setAllVars: false # optional: true to export NBGV_* env vars
62+
toolVersion: 3.8.38-alpha # keep behavior pinned
63+
setAllVars: false
4764

48-
- name: Sanity-check release type vs computed version
65+
- name: Sanity-check - requested prerelease vs computed version
4966
run: |
5067
PRE="${{ steps.nbgv.outputs.PrereleaseVersion }}"
5168
if [[ "${{ inputs.is_prerelease }}" == "true" && -z "$PRE" ]]; then
52-
echo "Requested prerelease but NBGV computed a stable version."
69+
echo "Requested prerelease, but NBGV computed a STABLE version."
5370
exit 1
5471
fi
5572
if [[ "${{ inputs.is_prerelease }}" == "false" && -n "$PRE" ]]; then
56-
echo "Requested stable release but NBGV computed a prerelease ($PRE)."
73+
echo "Requested STABLE, but NBGV computed a PRERELEASE ($PRE)."
5774
exit 1
5875
fi
5976
6077
- name: Tag current commit with NBGV
6178
run: |
6279
git config user.name "${{ github.actor }}"
6380
git config user.email "${{ github.actor }}@users.noreply.github.com"
64-
nbgv tag || echo "Tag may already exist."
65-
git push origin "v${{ steps.nbgv.outputs.NuGetPackageVersion }}" || echo "Tag exists on remote."
81+
# Creates annotated tag v{NuGetPackageVersion} at HEAD
82+
nbgv tag || echo "Tag may already exist locally."
83+
git push origin "v${{ steps.nbgv.outputs.NuGetPackageVersion }}" || echo "Tag already exists on remote."
6684
6785
- name: Create GitHub Release
6886
env:
@@ -71,9 +89,14 @@ jobs:
7189
FLAGS=()
7290
[[ "${{ inputs.is_draft }}" == "true" ]] && FLAGS+=(--draft)
7391
[[ "${{ inputs.is_prerelease }}" == "true" ]] && FLAGS+=(--prerelease)
74-
if [[ "${{ github.ref }}" == "refs/heads/main" && "${{ inputs.is_prerelease }}" != "true" ]]; then
75-
FLAGS+=(--latest)
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
7698
fi
99+
77100
TAG="v${{ steps.nbgv.outputs.NuGetPackageVersion }}"
78-
echo "Creating release ${TAG}"
101+
echo "Creating release ${TAG} from '${{ inputs.target_branch }}'"
79102
gh release create "${TAG}" --title "${TAG}" --generate-notes "${FLAGS[@]}"

0 commit comments

Comments
 (0)