Skip to content

Commit 468d210

Browse files
committed
chore: add auto-detect to bump-release workflow
1 parent d487304 commit 468d210

1 file changed

Lines changed: 54 additions & 3 deletions

File tree

.github/workflows/bump-release.yml

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ on:
44
workflow_dispatch:
55
inputs:
66
bump:
7-
description: "Version bump type"
7+
description: "Version bump type (leave 'auto' to detect from commit messages)"
88
required: true
99
type: choice
10+
default: auto
1011
options:
12+
- auto
1113
- patch
1214
- minor
1315
- major
@@ -21,22 +23,71 @@ jobs:
2123
steps:
2224
- uses: actions/checkout@v4
2325
with:
26+
fetch-depth: 0
2427
token: ${{ secrets.GITHUB_TOKEN }}
2528

29+
- name: Detect bump type from commits
30+
id: detect
31+
run: |
32+
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
33+
if [ -z "$LAST_TAG" ]; then
34+
RANGE="HEAD"
35+
else
36+
RANGE="${LAST_TAG}..HEAD"
37+
fi
38+
39+
COMMITS=$(git log --pretty=format:"%s" "$RANGE")
40+
echo "## Commits since $LAST_TAG:"
41+
echo "$COMMITS"
42+
echo ""
43+
44+
BUMP="patch"
45+
if echo "$COMMITS" | grep -qiE "^feat(\(.*\))?!:|BREAKING CHANGE"; then
46+
BUMP="major"
47+
elif echo "$COMMITS" | grep -qiE "^feat(\(.*\))?:"; then
48+
BUMP="minor"
49+
elif echo "$COMMITS" | grep -qiE "^(fix|perf)(\(.*\))?:"; then
50+
BUMP="patch"
51+
fi
52+
53+
echo "detected=$BUMP" >> "$GITHUB_OUTPUT"
54+
echo "Detected bump: $BUMP"
55+
56+
- name: Resolve bump type
57+
id: bump
58+
run: |
59+
if [ "${{ inputs.bump }}" = "auto" ]; then
60+
BUMP="${{ steps.detect.outputs.detected }}"
61+
else
62+
BUMP="${{ inputs.bump }}"
63+
fi
64+
echo "type=$BUMP" >> "$GITHUB_OUTPUT"
65+
echo "Using bump type: $BUMP"
66+
2667
- name: Compute new version
2768
id: version
2869
run: |
2970
CURRENT=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)"/\1/')
3071
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
31-
case "${{ inputs.bump }}" in
72+
case "${{ steps.bump.outputs.type }}" in
3273
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
3374
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
3475
patch) PATCH=$((PATCH + 1)) ;;
3576
esac
3677
NEW="${MAJOR}.${MINOR}.${PATCH}"
3778
echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
3879
echo "new=$NEW" >> "$GITHUB_OUTPUT"
39-
echo "Bumping $CURRENT -> $NEW"
80+
81+
- name: Summary
82+
run: |
83+
echo "### Release Summary" >> "$GITHUB_STEP_SUMMARY"
84+
echo "" >> "$GITHUB_STEP_SUMMARY"
85+
echo "| | |" >> "$GITHUB_STEP_SUMMARY"
86+
echo "|---|---|" >> "$GITHUB_STEP_SUMMARY"
87+
echo "| **Current** | v${{ steps.version.outputs.current }} |" >> "$GITHUB_STEP_SUMMARY"
88+
echo "| **New** | v${{ steps.version.outputs.new }} |" >> "$GITHUB_STEP_SUMMARY"
89+
echo "| **Bump** | ${{ steps.bump.outputs.type }} |" >> "$GITHUB_STEP_SUMMARY"
90+
echo "| **Auto-detected** | ${{ steps.detect.outputs.detected }} |" >> "$GITHUB_STEP_SUMMARY"
4091
4192
- name: Bump Cargo.toml
4293
run: sed -i "0,/^version = \".*\"/s//version = \"${{ steps.version.outputs.new }}\"/" Cargo.toml

0 commit comments

Comments
 (0)