Skip to content

Commit 1d6ed51

Browse files
authored
Improve release workflow (#45)
* Checks if a branch is named "release/VERSION" whereas VERSION is a semver version of "MAJOR.MINOR.PATCH" * The workflow is triggered when the respective branch is merged to main * After a successful merge, it builds the wheel and creates a new release with auto-generated release notes
1 parent 2a921ed commit 1d6ed51

2 files changed

Lines changed: 64 additions & 11 deletions

File tree

.github/workflows/release.yml

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,73 @@
1-
name: Create Release
1+
name: Release on Merge
22

33
on:
4-
push:
5-
tags:
6-
- '[0-9]+.[0-9]+.[0-9]+'
7-
8-
permissions:
9-
contents: write
10-
# discussions: write
4+
pull_request:
5+
types: [closed]
6+
branches: [main]
117

128
jobs:
13-
create_release:
9+
check-release-branch:
10+
runs-on: ubuntu-latest
11+
# This if clause ensures the job only runs when the PR is merged
12+
# and the branch starts with release/
13+
if: |
14+
github.event.pull_request.merged == true &&
15+
startsWith(github.event.pull_request.head.ref, 'release/')
16+
17+
outputs:
18+
valid_release: ${{ steps.validate.outputs.valid_release }}
19+
version: ${{ steps.validate.outputs.version }}
20+
21+
steps:
22+
- name: Validate release branch and extract version
23+
id: validate
24+
run: |
25+
BRANCH="${{ github.event.pull_request.head.ref }}"
26+
if [[ "$BRANCH" =~ ^release/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
27+
VERSION="${BASH_REMATCH[1]}"
28+
echo "valid_release=true" >> "$GITHUB_OUTPUT"
29+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
30+
echo "Branch name valid for release: $BRANCH"
31+
else
32+
echo "valid_release=false" >> "$GITHUB_OUTPUT"
33+
echo "version=" >> "$GITHUB_OUTPUT"
34+
echo "Branch '$BRANCH' does not match release/X.Y.Z (semver) pattern. Skipping release."
35+
fi
36+
37+
do-release:
38+
needs: check-release-branch
39+
if: needs.check-release-branch.outputs.valid_release == 'true'
1440
runs-on: ubuntu-latest
41+
env:
42+
VERSION: ${{ needs.check-release-branch.outputs.version }}
43+
1544
steps:
16-
- name: Generate GitHub Release
45+
- name: Checkout code
46+
uses: actions/checkout@v4
47+
48+
- name: Setup uv
49+
id: setup-uv
50+
uses: astral-sh/setup-uv@v1
51+
52+
- name: Print the installed version
53+
run: |
54+
echo "uv version is ${{ steps.setup-uv.outputs.uv-version }}"
55+
56+
- name: Tag new release
57+
run: |
58+
git config user.name 'github-actions[bot]'
59+
git config user.email 'github-actions[bot]@users.noreply.github.com'
60+
git tag "${{ env.VERSION }}"
61+
git push origin "${{ env.VERSION }}"
62+
63+
- name: Build wheel
64+
run: uv build --wheel
65+
66+
- name: Generate GitHub Release & Upload wheel
1767
uses: softprops/action-gh-release@v2
1868
with:
69+
tag_name: ${{ env.VERSION }}
1970
generate_release_notes: true
71+
files: dist/*.whl
2072
env:
21-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

changelog.d/45.infra.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve release workflow

0 commit comments

Comments
 (0)