Skip to content

Commit 8d6e401

Browse files
committed
feat: enhance version handling in release workflow for manual triggers
- Support version extraction for both tag and manual triggers. - Increment patch version for manual releases based on the latest tag. - Create and push a tag when a manual trigger is detected. - Initialize version to v1.0.0 if no previous tags exist.
1 parent 0d607d7 commit 8d6e401

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

.github/workflows/release.yml

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,23 @@ jobs:
115115
116116
- name: Generate Changelog
117117
run: |
118-
# Extract version without refs prefix
119-
VERSION="${GITHUB_REF#refs/tags/}"
120-
121-
# Verify this is actually a tag, not a branch
122-
if [[ "$GITHUB_REF" != refs/tags/* ]]; then
123-
echo "Error: This workflow should only run on tags, but got: $GITHUB_REF"
124-
exit 1
118+
# Handle version extraction for both tag and manual triggers
119+
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
120+
# Extract version from tag
121+
VERSION="${GITHUB_REF#refs/tags/}"
122+
echo "Running on tag: $VERSION"
123+
else
124+
# For manual triggers, get the latest tag or create a version based on commit
125+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
126+
if [ -n "$LATEST_TAG" ]; then
127+
# Increment patch version for manual release
128+
VERSION="${LATEST_TAG%.*}.$((${LATEST_TAG##*.} + 1))"
129+
echo "Manual trigger: incrementing from $LATEST_TAG to $VERSION"
130+
else
131+
# No tags exist, start with v1.0.0
132+
VERSION="v1.0.0"
133+
echo "No previous tags found, using initial version: $VERSION"
134+
fi
125135
fi
126136
127137
echo "Generating changelog for version: $VERSION"
@@ -236,6 +246,9 @@ jobs:
236246
237247
echo "Generated changelog:"
238248
cat release_notes.md
249+
250+
# Export VERSION for use in subsequent steps
251+
echo "VERSION=$VERSION" >> $GITHUB_ENV
239252
240253
- name: Install GitHub CLI
241254
run: |
@@ -250,10 +263,17 @@ jobs:
250263
echo "Creating release with binaries:"
251264
ls -la dist/
252265
253-
# Extract version without refs prefix
254-
VERSION="${GITHUB_REF#refs/tags/}"
255266
echo "Using version: $VERSION"
256267
268+
# Create and push tag if this was a manual trigger (not already a tag)
269+
if [[ "$GITHUB_REF" != refs/tags/* ]]; then
270+
echo "Creating and pushing tag: $VERSION"
271+
git config user.name "github-actions[bot]"
272+
git config user.email "github-actions[bot]@users.noreply.github.com"
273+
git tag -a "$VERSION" -m "Release $VERSION"
274+
git push origin "$VERSION"
275+
fi
276+
257277
gh release create "$VERSION" \
258278
--title "Pingu $VERSION" \
259279
--notes-file release_notes.md \
@@ -270,8 +290,6 @@ jobs:
270290

271291
- name: Release Summary
272292
run: |
273-
# Extract version without refs prefix
274-
VERSION="${GITHUB_REF#refs/tags/}"
275293
echo "## 🎉 Release Summary" >> $GITHUB_STEP_SUMMARY
276294
echo "" >> $GITHUB_STEP_SUMMARY
277295
echo "✅ Successfully created release **$VERSION**" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)