Skip to content

Commit fcc4eb8

Browse files
jongioCopilot
andcommitted
ci: auto-version release workflow with patch/minor/major dropdown
Replace manual version string input with a choice dropdown (patch, minor, major). The workflow computes the next semver from the latest v* git tag automatically: patch: 0.1.1 -> 0.1.2 minor: 0.1.1 -> 0.2.0 major: 0.1.1 -> 1.0.0 Co-authored-by: Copilot <[email protected]>
1 parent ce8498e commit fcc4eb8

1 file changed

Lines changed: 44 additions & 5 deletions

File tree

.github/workflows/release.yml

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ name: Release
33
on:
44
workflow_dispatch:
55
inputs:
6-
version:
7-
description: "Release version (e.g., 0.2.0 — without 'v' prefix)"
6+
bump:
7+
description: "Release type"
88
required: true
9-
type: string
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
1014

1115
concurrency:
1216
group: release
@@ -35,12 +39,47 @@ jobs:
3539

3640
- uses: anchore/sbom-action/download-syft@e11c554f704a0b820cbf8c51673f6945e0731532 # v0
3741

42+
- name: Compute next version
43+
id: version
44+
run: |
45+
# Get the latest semver tag, default to v0.0.0 if none exists
46+
LATEST=$(git tag --list 'v*' --sort=-v:refname | head -n1)
47+
if [ -z "$LATEST" ]; then
48+
LATEST="v0.0.0"
49+
fi
50+
51+
# Strip the leading 'v'
52+
CURRENT="${LATEST#v}"
53+
54+
# Split into major.minor.patch
55+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
56+
57+
# Bump based on input
58+
case "${{ inputs.bump }}" in
59+
major)
60+
MAJOR=$((MAJOR + 1))
61+
MINOR=0
62+
PATCH=0
63+
;;
64+
minor)
65+
MINOR=$((MINOR + 1))
66+
PATCH=0
67+
;;
68+
patch)
69+
PATCH=$((PATCH + 1))
70+
;;
71+
esac
72+
73+
NEXT="${MAJOR}.${MINOR}.${PATCH}"
74+
echo "version=${NEXT}" >> "$GITHUB_OUTPUT"
75+
echo "Bumping ${CURRENT} -> ${NEXT} (${{ inputs.bump }})"
76+
3877
- name: Create and push tag
3978
run: |
4079
git config user.name "github-actions[bot]"
4180
git config user.email "github-actions[bot]@users.noreply.github.com"
42-
git tag -a "v${{ inputs.version }}" -m "v${{ inputs.version }}"
43-
git push origin "v${{ inputs.version }}"
81+
git tag -a "v${{ steps.version.outputs.version }}" -m "v${{ steps.version.outputs.version }}"
82+
git push origin "v${{ steps.version.outputs.version }}"
4483
4584
- uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6
4685
with:

0 commit comments

Comments
 (0)