Skip to content

Commit 8658d25

Browse files
Enum the release version (#2082)
* Enum the release version * Fix tag selection * Bail build if no tag is found * Lint fix
1 parent cbdfc79 commit 8658d25

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

.github/workflows/build.yml

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ name: Release
33
on:
44
workflow_dispatch:
55
inputs:
6-
version:
6+
version_bump:
77
required: true
8-
description: 'Release version'
8+
description: 'Version bump type'
9+
type: choice
10+
options:
11+
- major
12+
- minor
913

1014
jobs:
1115
release_pr:
@@ -39,6 +43,44 @@ jobs:
3943
git checkout -b releases origin/releases
4044
fi
4145
46+
- name: Calculate next version
47+
id: version
48+
run: |
49+
# Get the latest tag (no longer using v prefix, filter out legacy v-prefixed tags)
50+
LATEST_TAG=$(git tag | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1)
51+
52+
# Stop build if no version tag is found
53+
if [ -z "$LATEST_TAG" ]; then
54+
echo "Error: No semantic version tags found in repository"
55+
echo "Expected format: X.Y.Z (e.g., 12.5.0)"
56+
exit 1
57+
fi
58+
59+
echo "Latest tag found: $LATEST_TAG"
60+
61+
# Extract version numbers (remove 'v' prefix if present for backwards compatibility)
62+
VERSION_WITHOUT_V=${LATEST_TAG#v}
63+
64+
# Parse major and minor (ignore patch since we don't support it)
65+
MAJOR=$(echo $VERSION_WITHOUT_V | cut -d. -f1)
66+
MINOR=$(echo $VERSION_WITHOUT_V | cut -d. -f2)
67+
68+
# Calculate next version based on input
69+
if [ "${{ github.event.inputs.version_bump }}" = "major" ]; then
70+
NEXT_MAJOR=$((MAJOR + 1))
71+
NEXT_MINOR=0
72+
else
73+
NEXT_MAJOR=$MAJOR
74+
NEXT_MINOR=$((MINOR + 1))
75+
fi
76+
77+
# Create new version (always without v prefix)
78+
NEXT_VERSION="${NEXT_MAJOR}.${NEXT_MINOR}.0"
79+
80+
echo "Next version: $NEXT_VERSION"
81+
echo "RELEASE_VERSION=$NEXT_VERSION" >> $GITHUB_ENV
82+
echo "version=$NEXT_VERSION" >> $GITHUB_OUTPUT
83+
4284
- name: Collect commit ranges
4385
run: |
4486
bash ./scripts/changelog.sh > ${{ github.workspace }}/CHANGELOG.txt
@@ -69,7 +111,7 @@ jobs:
69111
- name: Commit build files
70112
uses: stefanzweifel/git-auto-commit-action@v7
71113
with:
72-
commit_message: 'Release build ${{ github.event.inputs.version }} [ci release]'
114+
commit_message: 'Release build ${{ steps.version.outputs.version }} [ci release]'
73115
commit_options: '--allow-empty'
74116
skip_checkout: true
75117
branch: 'releases'
@@ -87,5 +129,5 @@ jobs:
87129
body_path: ${{ github.workspace }}/CHANGELOG.txt
88130
draft: false
89131
prerelease: false
90-
tag_name: ${{ github.event.inputs.version }}
132+
tag_name: ${{ steps.version.outputs.version }}
91133
target_commitish: 'releases'

0 commit comments

Comments
 (0)