Skip to content

Commit 475cee1

Browse files
committed
Fix hotfix tag incrementing for multiple PRs merged to branch
Extract base version from existing hotfix tags and use stricter regex to count only relevant hotfix tags. This ensures each PR merge creates the next hotfix number correctly (e.g., hotfix-1, hotfix-2, etc.).
1 parent 4409d73 commit 475cee1

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

.github/workflows/release-docs.yml

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,26 @@ jobs:
4242
4343
- name: Get the current version
4444
run: |
45-
echo "CURRENT_VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
45+
LATEST_TAG=$(git describe --tags --abbrev=0)
46+
47+
# Extract base version (remove hotfix suffix if present)
48+
if [[ $LATEST_TAG =~ -hotfix-[0-9]+$ ]]; then
49+
# It's a hotfix tag, extract the base version
50+
CURRENT_VERSION="${LATEST_TAG%-hotfix-*}"
51+
else
52+
# It's a regular tag
53+
CURRENT_VERSION="$LATEST_TAG"
54+
fi
55+
56+
echo "Latest tag: $LATEST_TAG"
57+
echo "Current version: $CURRENT_VERSION"
58+
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
59+
shell: bash
4660

4761
- name: Increment version
4862
run: |
4963
NEW_VERSION="${{ github.event.inputs.version }}"
50-
64+
5165
if [[ -z "$NEW_VERSION" ]]; then
5266
set -euxo pipefail
5367
IFS='.' read -r MAJOR MINOR PATCH <<< "${{ env.CURRENT_VERSION }}"
@@ -58,7 +72,7 @@ jobs:
5872
PATCH=$((PATCH+1))
5973
echo "Version is auto incremented."
6074
fi
61-
75+
6276
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
6377
fi
6478
@@ -70,24 +84,18 @@ jobs:
7084
if: ${{ env.IS_HOTFIX == 'true' }}
7185
run: |
7286
set +e
73-
74-
# Determine the hotfix tag
75-
# echo "Determining the hotfix tag..."
7687
77-
hotfix_count=$(git tag | grep -E "${{ env.NEW_VERSION }}-hotfix-[0-9]+" | wc -l)
88+
# Count existing hotfix tags for the current version
89+
hotfix_count=$(git tag | grep -E "^${{ env.NEW_VERSION }}-hotfix-[0-9]+$" | wc -l)
7890
echo "Hotfix count: $hotfix_count"
7991
8092
next_hotfix_no=$((hotfix_count + 1))
8193
echo "Next Hotfix number: $next_hotfix_no"
8294
83-
# Replace the last digit with the incremented value
84-
hotfix_release_tag=${{ env.NEW_VERSION }}-hotfix-$next_hotfix_no
95+
hotfix_release_tag="${{ env.NEW_VERSION }}-hotfix-${next_hotfix_no}"
8596
echo "Hotfix release tag: $hotfix_release_tag"
8697
87-
# set the new version to the hotfix version
88-
NEW_VERSION=$(echo $hotfix_release_tag)
89-
90-
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
98+
echo "NEW_VERSION=$hotfix_release_tag" >> $GITHUB_ENV
9199
92100
shell: bash
93101

0 commit comments

Comments
 (0)