From ac6a23ae974b7b9fa5ce3a66be1530813dd55d46 Mon Sep 17 00:00:00 2001 From: scott45 Date: Fri, 17 Oct 2025 14:47:02 +0300 Subject: [PATCH] fix: correct minor bump for feat: and improve notes --- .github/workflows/release.yml | 43 +++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bca549f..0435b6f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Prepare Release +name: Prepare and Publish Release on: push: branches: @@ -18,29 +18,42 @@ jobs: echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list sudo apt update && sudo apt install gh -y gh auth login --with-token <<< ${{ secrets.DEMO_GITHUB_TOKEN }} - - name: Generate Release Notes and Tag + - name: Generate Release and Publish 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 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 (only one level bumps) - NEW_MAJOR=$((CURRENT_MAJOR + MAJOR)) - NEW_MINOR=$((CURRENT_MINOR + MINOR * (1 - MAJOR))) - NEW_PATCH=$((CURRENT_PATCH + PATCH * (1 - MAJOR) * (1 - MINOR))) + # Calculate new version with safety check + 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)) + NEW_MINOR=$((CURRENT_MINOR + MINOR * (1 - MAJOR))) + NEW_PATCH=$((CURRENT_PATCH + PATCH * (1 - MAJOR) * (1 - MINOR))) + fi TAG="v${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}" - # 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") - # Create tag and draft release + # Ensure tag is new + if git rev-parse "$TAG" >/dev/null 2>&1; then + echo "Tag $TAG already exists, incrementing patch..." + NEW_PATCH=$((NEW_PATCH + 1)) + TAG="v${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}" + fi + 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 gh release create $TAG --title "Release ${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}" --notes "$NOTES" - # gh release create $TAG --title "Release ${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}" --notes "$NOTES" --draft