Skip to content

Commit bf4592f

Browse files
committed
feat(release): add support for manual version input in workflow dispatch
1 parent 29f41e6 commit bf4592f

3 files changed

Lines changed: 66 additions & 15 deletions

File tree

.github/workflows/release.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ on:
99
- 'templates/**'
1010
- '.github/workflows/**'
1111
workflow_dispatch:
12+
inputs:
13+
release_version:
14+
description: 'Optional release version (e.g., 1.4.6 or v1.4.6). If omitted, workflow auto-selects.'
15+
required: false
16+
type: string
1217

1318
jobs:
1419
release:
@@ -26,7 +31,7 @@ jobs:
2631
id: get_tag
2732
run: |
2833
chmod +x .github/workflows/scripts/get-next-version.sh
29-
.github/workflows/scripts/get-next-version.sh
34+
.github/workflows/scripts/get-next-version.sh "${{ github.event.inputs.release_version || '' }}"
3035
- name: Check if release already exists
3136
id: check_release
3237
run: |

.github/workflows/scripts/get-next-version.sh

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,66 @@
22
set -euo pipefail
33

44
# get-next-version.sh
5-
# Calculate the next version based on the latest git tag and output GitHub Actions variables
6-
# Usage: get-next-version.sh
5+
# Calculate release version and output GitHub Actions variables
6+
# Usage: get-next-version.sh [explicit_version]
77
# Uses standard semantic versioning (MAJOR.MINOR.PATCH)
88

99
# Get the latest tag, or use v0.0.0 if no tags exist
1010
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
1111
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
1212

13-
# Parse semantic version
14-
if [[ $LATEST_TAG =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
15-
# Increment patch version
16-
MAJOR=${BASH_REMATCH[1]}
17-
MINOR=${BASH_REMATCH[2]}
18-
PATCH=${BASH_REMATCH[3]}
19-
PATCH=$((PATCH + 1))
20-
NEW_VERSION="v$MAJOR.$MINOR.$PATCH"
21-
else
22-
# First release - start with v1.0.0
23-
NEW_VERSION="v1.0.0"
13+
EXPLICIT_VERSION="${1:-}"
14+
15+
normalize_version() {
16+
local raw="$1"
17+
raw="${raw#v}"
18+
if [[ $raw =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
19+
echo "v$raw"
20+
return 0
21+
fi
22+
return 1
23+
}
24+
25+
increment_patch() {
26+
local tag="$1"
27+
if [[ $tag =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
28+
local major="${BASH_REMATCH[1]}"
29+
local minor="${BASH_REMATCH[2]}"
30+
local patch="${BASH_REMATCH[3]}"
31+
patch=$((patch + 1))
32+
echo "v$major.$minor.$patch"
33+
return 0
34+
fi
35+
echo "v1.0.0"
36+
}
37+
38+
# 1) Explicit manual input wins (workflow_dispatch input)
39+
if [[ -n "$EXPLICIT_VERSION" ]]; then
40+
if NEW_VERSION=$(normalize_version "$EXPLICIT_VERSION"); then
41+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
42+
echo "New version will be: $NEW_VERSION (source: explicit input)"
43+
exit 0
44+
else
45+
echo "Invalid explicit version '$EXPLICIT_VERSION'. Use MAJOR.MINOR.PATCH (optionally prefixed with v)." >&2
46+
exit 1
47+
fi
2448
fi
2549

50+
# 2) Prefer pyproject.toml version when present and not already tagged
51+
if [[ -f "pyproject.toml" ]]; then
52+
PYPROJECT_VERSION=$(grep -oE '^[[:space:]]*version[[:space:]]*=[[:space:]]*"[0-9]+\.[0-9]+\.[0-9]+"' pyproject.toml | head -n1 | sed -E 's/.*"([0-9]+\.[0-9]+\.[0-9]+)"/\1/')
53+
if [[ -n "${PYPROJECT_VERSION:-}" ]]; then
54+
CANDIDATE_VERSION="v$PYPROJECT_VERSION"
55+
if ! git rev-parse -q --verify "refs/tags/$CANDIDATE_VERSION" >/dev/null 2>&1; then
56+
echo "new_version=$CANDIDATE_VERSION" >> $GITHUB_OUTPUT
57+
echo "New version will be: $CANDIDATE_VERSION (source: pyproject.toml)"
58+
exit 0
59+
fi
60+
fi
61+
fi
62+
63+
# 3) Fallback: increment latest tag
64+
NEW_VERSION=$(increment_patch "$LATEST_TAG")
65+
2666
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
27-
echo "New version will be: $NEW_VERSION"
67+
echo "New version will be: $NEW_VERSION (source: latest tag increment)"

templates/commands/release.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@ Confirm these three sources agree on {NEXT_VERSION}:
376376

377377
If any are out of sync, fix before tagging.
378378

379+
#### D. Manual workflow dispatch version (recommended)
380+
381+
When running **Create Release** via `workflow_dispatch`, set `release_version` to
382+
`{NEXT_VERSION}` (or `v{NEXT_VERSION}`) so the workflow publishes the intended tag
383+
instead of auto-incrementing from the latest existing tag.
384+
379385
### 10. Clean Slate Preparation
380386

381387
After archival (skip if DRY_RUN):

0 commit comments

Comments
 (0)