Skip to content

Commit d68cfee

Browse files
committed
automate release flow
1 parent aaf2930 commit d68cfee

File tree

3 files changed

+142
-47
lines changed

3 files changed

+142
-47
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,26 @@ jobs:
3939

4040
- name: Test
4141
run: uv run pytest
42+
43+
smoke-test:
44+
name: Smoke test (Python ${{ matrix.python }})
45+
if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'version-bump')
46+
runs-on: ubuntu-latest
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
51+
steps:
52+
- uses: actions/checkout@v3
53+
- uses: astral-sh/setup-uv@v7
54+
with:
55+
python-version: ${{ matrix.python }}
56+
57+
- name: Build
58+
run: uv build
59+
60+
- name: Smoke test (wheel)
61+
run: uv run --isolated --no-project --with dist/*.whl tests/smoke_test.py
62+
63+
- name: Smoke test (sdist)
64+
run: uv run --isolated --no-project --with dist/*.tar.gz tests/smoke_test.py

.github/workflows/release.yml

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,61 @@
11
name: Release
22

33
on:
4-
# Support manually pushing a new release
5-
workflow_dispatch: {}
6-
# Trigger when a release or pre-release is published
7-
release:
8-
types: [published]
4+
pull_request:
5+
types: [closed]
6+
branches: [main]
97

108
defaults:
119
run:
1210
shell: bash
1311

1412
jobs:
15-
build:
16-
name: Build distribution
13+
create-release:
14+
name: Create GitHub Release
15+
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'version-bump')
1716
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
1819
steps:
19-
- name: Checkout
20-
uses: actions/checkout@v5
21-
- name: Install uv
22-
uses: astral-sh/setup-uv@v6
23-
- name: Build
24-
run: uv build
25-
- name: Upload artifacts
26-
uses: actions/upload-artifact@v4
20+
- name: Generate token
21+
id: generate-token
22+
uses: actions/create-github-app-token@v1
2723
with:
28-
name: dist
29-
path: dist/
24+
app-id: ${{ vars.WORKOS_BOT_APP_ID }}
25+
private-key: ${{ secrets.WORKOS_BOT_PRIVATE_KEY }}
3026

31-
smoke-test:
32-
name: Smoke test (Python ${{ matrix.python }})
33-
needs: build
34-
runs-on: ubuntu-latest
35-
strategy:
36-
fail-fast: false
37-
matrix:
38-
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
39-
steps:
4027
- name: Checkout
41-
uses: actions/checkout@v5
42-
- name: Install uv
43-
uses: astral-sh/setup-uv@v6
28+
uses: actions/checkout@v4
4429
with:
45-
python-version: ${{ matrix.python }}
46-
cache-python: true
47-
- name: Download artifacts
48-
uses: actions/download-artifact@v4
30+
token: ${{ steps.generate-token.outputs.token }}
31+
32+
- name: Get version from pyproject.toml
33+
id: get-version
34+
run: |
35+
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
36+
echo "version=$VERSION" >> $GITHUB_OUTPUT
37+
38+
- name: Create Release
39+
uses: softprops/action-gh-release@v2
4940
with:
50-
name: dist
51-
path: dist/
52-
- name: Smoke test (wheel)
53-
run: uv run --python ${{ matrix.python }} --isolated --no-project --with dist/*.whl tests/smoke_test.py
54-
- name: Smoke test (source distribution)
55-
run: uv run --python ${{ matrix.python }} --isolated --no-project --with dist/*.tar.gz tests/smoke_test.py
41+
tag_name: v${{ steps.get-version.outputs.version }}
42+
name: v${{ steps.get-version.outputs.version }}
43+
generate_release_notes: true
44+
token: ${{ steps.generate-token.outputs.token }}
5645

5746
publish:
5847
name: Publish to PyPI
59-
needs: smoke-test
48+
needs: create-release
6049
runs-on: ubuntu-latest
61-
environment:
62-
name: pypi
6350
permissions:
6451
id-token: write
6552
contents: read
6653
steps:
67-
- name: Download artifacts
68-
uses: actions/download-artifact@v4
69-
with:
70-
name: dist
71-
path: dist/
54+
- name: Checkout
55+
uses: actions/checkout@v4
7256
- name: Install uv
7357
uses: astral-sh/setup-uv@v6
58+
- name: Build
59+
run: uv build
7460
- name: Publish
7561
run: uv publish

.github/workflows/version-bump.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Version Bump
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
bump_type:
7+
description: "Version bump type"
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
15+
jobs:
16+
bump-version:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
steps:
22+
- name: Generate token
23+
id: generate-token
24+
uses: actions/create-github-app-token@v1
25+
with:
26+
app-id: ${{ vars.WORKOS_BOT_APP_ID }}
27+
private-key: ${{ secrets.WORKOS_BOT_PRIVATE_KEY }}
28+
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
token: ${{ steps.generate-token.outputs.token }}
33+
34+
- name: Configure Git
35+
run: |
36+
git config user.name "workos-bot[bot]"
37+
git config user.email "workos-bot[bot]@users.noreply.github.com"
38+
39+
- name: Read current version
40+
id: current-version
41+
run: |
42+
CURRENT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
43+
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
44+
45+
- name: Bump version
46+
id: bump-version
47+
run: |
48+
CURRENT_VERSION="${{ steps.current-version.outputs.version }}"
49+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
50+
51+
case "${{ github.event.inputs.bump_type }}" in
52+
major)
53+
NEW_VERSION="$((MAJOR + 1)).0.0"
54+
;;
55+
minor)
56+
NEW_VERSION="$MAJOR.$((MINOR + 1)).0"
57+
;;
58+
patch)
59+
NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
60+
;;
61+
esac
62+
63+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
64+
65+
- name: Install uv
66+
uses: astral-sh/setup-uv@v6
67+
68+
- name: Update version in pyproject.toml
69+
run: |
70+
sed -i 's/^version = ".*"/version = "${{ steps.bump-version.outputs.new_version }}"/' pyproject.toml
71+
72+
- name: Update uv.lock
73+
run: uv lock
74+
75+
- name: Create Pull Request
76+
uses: peter-evans/create-pull-request@v7
77+
with:
78+
token: ${{ steps.generate-token.outputs.token }}
79+
commit-message: "v${{ steps.bump-version.outputs.new_version }}"
80+
title: "v${{ steps.bump-version.outputs.new_version }}"
81+
body: |
82+
Bumps version from ${{ steps.current-version.outputs.version }} to ${{ steps.bump-version.outputs.new_version }}.
83+
84+
This PR was automatically created by the version-bump workflow.
85+
branch: version-bump-${{ steps.bump-version.outputs.new_version }}
86+
labels: version-bump

0 commit comments

Comments
 (0)