Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ jobs:
run: |
# Get last tag or default to v1.0.0
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0.0")
# Extract PR title prefix from merge commit message (e.g., "Merge pull request #X from ... feat!: release v1.0.0")
PR_TITLE=$(git log -1 --merges --pretty=%s | sed 's/Merge pull request #[0-9]\+ from .*//;s/ .*//')
echo "Last tag: $LAST_TAG"
# Extract PR title prefix from merge commit message
PR_TITLE=$(git log -1 --merges --pretty=%s | sed 's/Merge pull request #[0-9]\+ from .*//')
echo "PR title prefix: $PR_TITLE"
# Determine version bump based on PR title prefix
MAJOR=$(echo "$PR_TITLE" | grep -q "^feat!:" && echo 1 || echo 0)
MINOR=$(echo "$PR_TITLE" | grep -q "^\(feat:\|fix:\|refactor:\)" && echo 1 || echo 0)
PATCH=$(echo "$PR_TITLE" | grep -q "^\(chore:\|docs:\|test:\)" && echo 1 || echo 0)
MAJOR=$(echo "$PR_TITLE" | grep -E "^feat!:" && echo 1 || echo 0)
MINOR=$(echo "$PR_TITLE" | grep -E "^feat:" && echo 1 || echo 0) # Prioritize feat: for minor
PATCH=$(echo "$PR_TITLE" | grep -E "^\(fix:\|refactor:\|chore:\|docs:\|test:\)" && echo 1 || echo 0)
# Parse current version
CURRENT_MAJOR=$(echo $LAST_TAG | sed 's/v\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)/\1/')
CURRENT_MINOR=$(echo $LAST_TAG | sed 's/v\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)/\2/')
CURRENT_PATCH=$(echo $LAST_TAG | sed 's/v\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)/\3/')
# Calculate new version with safety check
if [ "$TAG" = "$LAST_TAG" ]; then
if [ "$TAG" = "$LAST_TAG" ] || [ $MAJOR -eq 0 ] && [ $MINOR -eq 0 ] && [ $PATCH -eq 0 ]; then
NEW_PATCH=$((CURRENT_PATCH + 1))
else
NEW_MAJOR=$((CURRENT_MAJOR + MAJOR))
Expand All @@ -47,8 +49,10 @@ jobs:
NEW_PATCH=$((NEW_PATCH + 1))
TAG="v${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
fi
# Extract notes from commits since last tag
NOTES=$(git log $LAST_TAG..HEAD --pretty=format:"- %s" | grep -E "^(feat|fix|chore|docs|test|refactor):" || echo "Initial release")
echo "New tag: $TAG"
# Extract notes from commits since last tag, including merge commit context
NOTES=$(git log $LAST_TAG..HEAD --first-parent --pretty=format:"- %s" | grep -E "^(feat|fix|chore|docs|test|refactor):" || echo "Initial release")
echo "Release notes: $NOTES"
# Create tag and publish release
git tag $TAG
git push origin $TAG
Expand Down
Loading