Skip to content

Commit 62163ae

Browse files
committed
one-click release process
1 parent 90ecedb commit 62163ae

1 file changed

Lines changed: 49 additions & 3 deletions

File tree

.github/workflows/release.yml

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
name: PyPI Release
22

33
on:
4-
push:
5-
tags:
6-
- "v[0-9].[0-9]+.[0-9]+*"
4+
workflow_dispatch:
5+
inputs:
6+
bump:
7+
description: "Version bump type"
8+
required: true
9+
type: choice
10+
options:
11+
- MINOR
12+
- BUGFIX
13+
default: BUGFIX
714

815
jobs:
916
release:
@@ -14,6 +21,44 @@ jobs:
1421
steps:
1522
- name: Checkout
1623
uses: actions/checkout@v4
24+
with:
25+
ref: ${{ github.event.repository.default_branch }}
26+
27+
- name: Bump version
28+
run: |
29+
CURRENT=$(sed -n 's/^__version__ = "\([0-9.]*\).*/\1/p' src/banks/__about__.py)
30+
IFS=. read -r major minor patch <<< "$CURRENT"
31+
case "${{ github.event.inputs.bump }}" in
32+
BUGFIX)
33+
patch=$((patch + 1))
34+
;;
35+
MINOR)
36+
minor=$((minor + 1))
37+
patch=0
38+
;;
39+
*)
40+
echo "Unexpected bump type: ${{ github.event.inputs.bump }}"
41+
exit 1
42+
;;
43+
esac
44+
VERSION="${major}.${minor}.${patch}"
45+
echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
46+
echo "Bumped ${CURRENT} -> ${VERSION} (${{ github.event.inputs.bump }})"
47+
48+
- name: Update __about__.py on default branch
49+
run: |
50+
git config user.name "github-actions[bot]"
51+
git config user.email "github-actions[bot]@users.noreply.github.com"
52+
sed -i "s/^__version__ = .*$/__version__ = \"${VERSION}\"/" src/banks/__about__.py
53+
git diff --quiet && exit 0
54+
git add src/banks/__about__.py
55+
git commit -m "chore: set __version__ to ${VERSION} [skip ci]"
56+
git push origin "${{ github.event.repository.default_branch }}"
57+
58+
- name: Create and push tag
59+
run: |
60+
git tag "v${VERSION}"
61+
git push origin "v${VERSION}"
1762
1863
- name: Install Hatch
1964
run: pip install hatch
@@ -29,5 +74,6 @@ jobs:
2974
- name: Create GitHub Release
3075
uses: ncipollo/release-action@v1
3176
with:
77+
tag: v${{ env.VERSION }}
3278
artifacts: "dist/*"
3379
generateReleaseNotes: true

0 commit comments

Comments
 (0)