1+ name : Auto Release
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ paths :
8+ - ' pyproject.toml'
9+ - ' CHANGELOG.md'
10+
11+ jobs :
12+ check-version-bump :
13+ runs-on : ubuntu-latest
14+ outputs :
15+ version : ${{ steps.get-version.outputs.version }}
16+ changelog : ${{ steps.get-changelog.outputs.changelog }}
17+ should_release : ${{ steps.check-changes.outputs.should_release }}
18+
19+ steps :
20+ - name : Checkout code
21+ uses : actions/checkout@v4
22+ with :
23+ fetch-depth : 0
24+
25+ - name : Get version from pyproject.toml
26+ id : get-version
27+ run : |
28+ VERSION=$(grep -m 1 "version = " pyproject.toml | sed 's/version = "\(.*\)"/\1/')
29+ echo "version=$VERSION" >> $GITHUB_OUTPUT
30+ echo "Current version: $VERSION"
31+
32+ - name : Get changelog entry
33+ id : get-changelog
34+ run : |
35+ VERSION=$(grep -m 1 "version = " pyproject.toml | sed 's/version = "\(.*\)"/\1/')
36+ CHANGELOG_ENTRY=$(awk -v ver="$VERSION" 'BEGIN{inSection=0} $0 ~ "^## \\["ver"\\]" {inSection=1; next} inSection==1 && $0 ~ "^## " {exit} inSection {print}' CHANGELOG.md | tr -d '\r')
37+ echo "changelog<<EOF" >> $GITHUB_OUTPUT
38+ echo "$CHANGELOG_ENTRY" >> $GITHUB_OUTPUT
39+ echo "EOF" >> $GITHUB_OUTPUT
40+
41+ - name : Check if this is a version bump commit
42+ id : check-changes
43+ run : |
44+ # Check if commit message indicates a version bump
45+ COMMIT_MSG=$(git log -1 --pretty=%B)
46+ if [[ "$COMMIT_MSG" == *"bump version"* ]]; then
47+ echo "should_release=true" >> $GITHUB_OUTPUT
48+ echo "Version bump detected, should create release"
49+ else
50+ echo "should_release=false" >> $GITHUB_OUTPUT
51+ echo "Not a version bump commit"
52+ fi
53+
54+ create-release :
55+ needs : check-version-bump
56+ if : needs.check-version-bump.outputs.should_release == 'true'
57+ runs-on : ubuntu-latest
58+
59+ steps :
60+ - name : Checkout code
61+ uses : actions/checkout@v4
62+
63+ - name : Create GitHub Release
64+ id : create_release
65+ uses : actions/create-release@v1
66+ env :
67+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
68+ with :
69+ tag_name : v${{ needs.check-version-bump.outputs.version }}
70+ release_name : Release v${{ needs.check-version-bump.outputs.version }}
71+ body : ${{ needs.check-version-bump.outputs.changelog }}
72+ draft : false
73+ prerelease : false
74+
75+ - name : Output Release URL
76+ run : echo "Released at ${{ steps.create_release.outputs.html_url }}"
0 commit comments