Skip to content

Commit cbae01b

Browse files
Copilotmatt-goldman
andcommitted
Fix preview label to properly create pre-release NuGet packages
The root cause was that anothrNick/github-tag-action ignores the PRERELEASE environment variable when running on the default branch (main), always creating production releases instead of preview releases. This fix: - Conditionally uses the existing action only for release labels - Manually creates preview tags with -preview suffix when preview label is present - Maintains existing norelease functionality - Properly sets all environment variables and outputs Co-authored-by: matt-goldman <[email protected]>
1 parent b0ab196 commit cbae01b

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,61 @@ jobs:
6363
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6464

6565

66-
- name: GitHub Tag Bump
67-
id: tag_bump
68-
if: env.NORELEASE != 'true'
66+
- name: GitHub Tag Bump (Release)
67+
id: tag_bump_release
68+
if: env.PRERELEASE == 'false' && env.NORELEASE != 'true'
6969
uses: anothrNick/[email protected]
7070
env:
7171
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7272
INITIAL_VERSION: 1.0.0
7373
DEFAULT_BUMP: ${{ env.BUMP }}
74-
PRERELEASE: ${{ env.PRERELEASE }}
75-
PRERELEASE_SUFFIX: 'preview'
74+
PRERELEASE: false
75+
76+
- name: Get Latest Tag
77+
id: get_latest_tag
78+
if: env.PRERELEASE == 'true' && env.NORELEASE != 'true'
79+
run: |
80+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "1.0.0")
81+
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
82+
83+
- name: Calculate Preview Version
84+
id: calc_preview_version
85+
if: env.PRERELEASE == 'true' && env.NORELEASE != 'true'
86+
run: |
87+
LATEST_TAG="${{ steps.get_latest_tag.outputs.latest_tag }}"
88+
# Remove 'v' prefix if present
89+
LATEST_TAG=${LATEST_TAG#v}
90+
91+
# Split version into parts
92+
IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_TAG"
93+
94+
# Bump version based on BUMP type
95+
if [[ "${{ env.BUMP }}" == "major" ]]; then
96+
MAJOR=$((MAJOR + 1))
97+
MINOR=0
98+
PATCH=0
99+
elif [[ "${{ env.BUMP }}" == "minor" ]]; then
100+
MINOR=$((MINOR + 1))
101+
PATCH=0
102+
else
103+
PATCH=$((PATCH + 1))
104+
fi
105+
106+
# Create preview version
107+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-preview"
108+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
109+
110+
- name: Create Preview Tag
111+
id: tag_bump_preview
112+
if: env.PRERELEASE == 'true' && env.NORELEASE != 'true'
113+
run: |
114+
NEW_VERSION="${{ steps.calc_preview_version.outputs.new_version }}"
115+
git tag "$NEW_VERSION"
116+
git push origin "$NEW_VERSION"
117+
echo "new_tag=$NEW_VERSION" >> $GITHUB_OUTPUT
76118
77119
outputs:
78-
new_version: ${{ steps.tag_bump.outputs.new_tag }}
120+
new_version: ${{ env.NORELEASE != 'true' && (steps.tag_bump_release.outputs.new_tag || steps.tag_bump_preview.outputs.new_tag) || '' }}
79121
norelease: ${{ env.NORELEASE }}
80122

81123

0 commit comments

Comments
 (0)