Skip to content

Commit 5b18d04

Browse files
committed
feat: auto release workflow
1 parent 8994e77 commit 5b18d04

1 file changed

Lines changed: 71 additions & 29 deletions

File tree

.github/workflows/release.yml

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@ name: Release
22

33
on:
44
push:
5-
tags:
6-
- 'v*'
5+
branches: [main]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version bump (major, minor, patch)'
10+
default: 'patch'
11+
type: choice
12+
options:
13+
- major
14+
- minor
15+
- patch
716

817
jobs:
918
release:
@@ -14,57 +23,90 @@ jobs:
1423
- uses: actions/checkout@v4
1524
with:
1625
fetch-depth: 0
26+
token: ${{ secrets.GITHUB_TOKEN }}
1727

18-
- name: Extract version
28+
- name: Determine version bump
1929
id: version
20-
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
30+
run: |
31+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
32+
BUMP="${{ github.event.inputs.version }}"
33+
else
34+
# Check last tag and commits to determine bump
35+
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
36+
FEAT_COUNT=$(git log --pretty=format:"%s" $LAST_TAG..HEAD | grep -c "^feat:" || echo "0")
37+
FIX_COUNT=$(git log --pretty=format:"%s" $LAST_TAG..HEAD | grep -c "^fix:" || echo "0")
38+
if [ "$FEAT_COUNT" -gt 0 ]; then
39+
BUMP="minor"
40+
elif [ "$FIX_COUNT" -gt 0 ]; then
41+
BUMP="patch"
42+
else
43+
BUMP="none"
44+
fi
45+
fi
46+
echo "bump=$BUMP" >> $GITHUB_OUTPUT
47+
48+
- name: Bump version and tag
49+
if: steps.version.outputs.bump != 'none'
50+
run: |
51+
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
52+
VERSION=$(echo $LAST_TAG | sed 's/v//')
53+
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
54+
55+
case "${{ steps.version.outputs.bump }}" in
56+
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
57+
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
58+
patch) PATCH=$((PATCH + 1)) ;;
59+
esac
60+
61+
NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}"
62+
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_OUTPUT
63+
echo "Creating tag: $NEW_TAG"
64+
git tag $NEW_TAG
65+
git push origin $NEW_TAG
2166
2267
- name: Generate release notes
68+
if: steps.version.outputs.bump != 'none'
2369
id: release_notes
2470
run: |
25-
# Parse conventional commits since last tag
26-
echo "## What's Changed" >> release_notes.md
71+
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "v0.0.0")
72+
73+
echo "## What's Changed" > release_notes.md
2774
echo "" >> release_notes.md
2875
29-
# Features (feat:)
30-
FEATS=$(git log --pretty=format:"%s" --after=$(git describe --tags --abbrev=0 2>/dev/null || echo "1970-01-01")..HEAD | grep "^feat:" | sed 's/^feat: /- /' || true)
76+
FEATS=$(git log --pretty=format:"%s" $LAST_TAG..HEAD | grep "^feat:" | sed 's/^feat: /- /' || true)
3177
if [ -n "$FEATS" ]; then
3278
echo "### ✨ Features" >> release_notes.md
3379
echo "$FEATS" >> release_notes.md
3480
echo "" >> release_notes.md
3581
fi
36-
37-
# Bug fixes (fix:)
38-
FIXES=$(git log --pretty=format:"%s" --after=$(git describe --tags --abbrev=0 2>/dev/null || echo "1970-01-01")..HEAD | grep "^fix:" | sed 's/^fix: /- /' || true)
82+
83+
FIXES=$(git log --pretty=format:"%s" $LAST_TAG..HEAD | grep "^fix:" | sed 's/^fix: /- /' || true)
3984
if [ -n "$FIXES" ]; then
4085
echo "### 🐛 Bug Fixes" >> release_notes.md
4186
echo "$FIXES" >> release_notes.md
4287
echo "" >> release_notes.md
4388
fi
44-
45-
# Other changes
46-
OTHERS=$(git log --pretty=format:"- %s (%an)" --after=$(git describe --tags --abbrev=0 2>/dev/null || echo "1970-01-01")..HEAD | grep -v "^feat:" | grep -v "^fix:" || true)
47-
if [ -n "$OTHERS" ]; then
48-
echo "### Other Changes" >> release_notes.md
49-
echo "$OTHERS" >> release_notes.md
50-
fi
51-
52-
# Get previous tag for comparison
53-
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
54-
if [ -n "$PREV_TAG" ]; then
89+
90+
DOCS=$(git log --pretty=format:"%s" $LAST_TAG..HEAD | grep "^docs:" | sed 's/^docs: /- /' || true)
91+
if [ -n "$DOCS" ]; then
92+
echo "### 📝 Documentation" >> release_notes.md
93+
echo "$DOCS" >> release_notes.md
5594
echo "" >> release_notes.md
56-
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/$PREV_TAG...${{ github.ref_name }}" >> release_notes.md
5795
fi
58-
59-
cat release_notes.md
96+
97+
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/$LAST_TAG...${{ steps.version.outputs.NEW_TAG }}" >> release_notes.md
6098
6199
- name: Create Release
100+
if: steps.version.outputs.bump != 'none'
62101
uses: softprops/action-gh-release@v1
63102
with:
64-
tag_name: ${{ github.ref }}
65-
name: Release v${{ steps.version.outputs.VERSION }}
103+
tag_name: ${{ steps.version.outputs.NEW_TAG }}
104+
name: Release ${{ steps.version.outputs.NEW_TAG }}
66105
body_path: release_notes.md
67106
draft: false
68-
prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'alpha') }}
69107
env:
70-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
110+
- name: No release needed
111+
if: steps.version.outputs.bump == 'none'
112+
run: echo "No breaking changes or new features - no release needed"

0 commit comments

Comments
 (0)