Skip to content

Commit b384ee6

Browse files
committed
✨ feat(ci): auto-create tags on manual workflow dispatch
When triggering the release workflow via workflow_dispatch, the tag is now automatically created on the current HEAD if it doesn't exist. Changes: - Configure git with github-actions[bot] credentials - Create annotated tag if it doesn't exist - Push tag to remote before proceeding with release - Preserve existing behavior for pre-existing tags This eliminates the manual step of creating tags before triggering the workflow, improving the release UX.
1 parent a5a8bd2 commit b384ee6

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

.github/workflows/release.yml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
# Release Types:
66
# - Stable: Push a tag (git tag v4.0.6 && git push origin v4.0.6)
77
# - Nightly: Automatic on every push to main branch (rolling release)
8-
# - Manual: Actions -> Release -> Run workflow -> Enter version (e.g., v4.0.6)
9-
#
10-
# IMPORTANT for Manual Releases:
11-
# The tag MUST exist before triggering the workflow. Create it first:
12-
# git tag v4.0.7 && git push origin v4.0.7
13-
# Then trigger the workflow with the same version.
8+
# - Manual: Actions -> Release -> Run workflow -> Enter version (e.g., v4.0.7)
9+
# The tag will be auto-created on the current HEAD if it doesn't exist.
1410

1511
name: Release
1612

@@ -79,30 +75,36 @@ jobs:
7975
echo "version_number=${VERSION#v}" >> $GITHUB_OUTPUT
8076
echo "Release version: $VERSION"
8177
82-
- name: Verify tag exists (manual trigger)
78+
- name: Setup Git for tagging (manual trigger)
8379
if: github.event_name == 'workflow_dispatch'
8480
run: |
85-
VERSION="${{ steps.version.outputs.version }}"
86-
# Fetch all tags to ensure we have the latest
87-
git fetch --tags --force
88-
if ! git rev-parse "refs/tags/$VERSION" >/dev/null 2>&1; then
89-
echo "::error::Tag '$VERSION' does not exist in the repository."
90-
echo "::error::Please create the tag first using:"
91-
echo "::error:: git tag $VERSION && git push origin $VERSION"
92-
echo ""
93-
echo "Available tags:"
94-
git tag --list 'v*' | tail -20
95-
exit 1
96-
fi
97-
echo "✓ Tag $VERSION exists and is valid"
81+
git config user.name "github-actions[bot]"
82+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
9883
99-
- name: Checkout tag (manual trigger)
84+
- name: Create or verify tag (manual trigger)
10085
if: github.event_name == 'workflow_dispatch'
10186
run: |
10287
VERSION="${{ steps.version.outputs.version }}"
103-
echo "Checking out tag: $VERSION"
104-
git checkout "refs/tags/$VERSION"
105-
echo "✓ Successfully checked out $VERSION"
88+
# Fetch all tags to ensure we have the latest
89+
git fetch --tags --force
90+
91+
if git rev-parse "refs/tags/$VERSION" >/dev/null 2>&1; then
92+
echo "✓ Tag $VERSION already exists"
93+
echo "Checking out existing tag..."
94+
git checkout "refs/tags/$VERSION"
95+
else
96+
echo "Tag $VERSION does not exist, creating it on current HEAD..."
97+
CURRENT_SHA=$(git rev-parse HEAD)
98+
echo "Creating tag $VERSION at commit $CURRENT_SHA"
99+
100+
# Create the tag locally
101+
git tag -a "$VERSION" -m "Release $VERSION"
102+
103+
# Push the tag to remote
104+
git push origin "$VERSION"
105+
106+
echo "✓ Tag $VERSION created and pushed successfully"
107+
fi
106108
107109
- name: Generate changelog
108110
id: changelog

0 commit comments

Comments
 (0)