Skip to content

Commit ef374ca

Browse files
Enum the release version
1 parent 841429d commit ef374ca

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

.github/workflows/build.yml

Lines changed: 42 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,40 @@ 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, handling both v-prefixed and non-prefixed tags
50+
LATEST_TAG=$(git tag --sort=-version:refname | head -1)
51+
echo "Latest tag found: $LATEST_TAG"
52+
53+
# Extract version numbers (remove 'v' prefix if present)
54+
VERSION_WITHOUT_V=${LATEST_TAG#v}
55+
56+
# Parse major and minor (ignore patch since we don't support it)
57+
MAJOR=$(echo $VERSION_WITHOUT_V | cut -d. -f1)
58+
MINOR=$(echo $VERSION_WITHOUT_V | cut -d. -f2)
59+
60+
# Calculate next version based on input
61+
if [ "${{ github.event.inputs.version_bump }}" = "major" ]; then
62+
NEXT_MAJOR=$((MAJOR + 1))
63+
NEXT_MINOR=0
64+
else
65+
NEXT_MAJOR=$MAJOR
66+
NEXT_MINOR=$((MINOR + 1))
67+
fi
68+
69+
# Create new version (maintain v prefix if original had one)
70+
if [[ $LATEST_TAG == v* ]]; then
71+
NEXT_VERSION="v${NEXT_MAJOR}.${NEXT_MINOR}.0"
72+
else
73+
NEXT_VERSION="${NEXT_MAJOR}.${NEXT_MINOR}.0"
74+
fi
75+
76+
echo "Next version: $NEXT_VERSION"
77+
echo "RELEASE_VERSION=$NEXT_VERSION" >> $GITHUB_ENV
78+
echo "version=$NEXT_VERSION" >> $GITHUB_OUTPUT
79+
4280
- name: Collect commit ranges
4381
run: |
4482
bash ./scripts/changelog.sh > ${{ github.workspace }}/CHANGELOG.txt
@@ -69,7 +107,7 @@ jobs:
69107
- name: Commit build files
70108
uses: stefanzweifel/git-auto-commit-action@v7
71109
with:
72-
commit_message: 'Release build ${{ github.event.inputs.version }} [ci release]'
110+
commit_message: 'Release build ${{ steps.version.outputs.version }} [ci release]'
73111
commit_options: '--allow-empty'
74112
skip_checkout: true
75113
branch: 'releases'
@@ -87,5 +125,5 @@ jobs:
87125
body_path: ${{ github.workspace }}/CHANGELOG.txt
88126
draft: false
89127
prerelease: false
90-
tag_name: ${{ github.event.inputs.version }}
128+
tag_name: ${{ steps.version.outputs.version }}
91129
target_commitish: 'releases'

0 commit comments

Comments
 (0)