Skip to content

Commit 2b4b998

Browse files
committed
Add automated release workflow
1 parent 74f2caf commit 2b4b998

6 files changed

Lines changed: 209 additions & 6 deletions

File tree

‎.github/pull_request_template.md‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@
88

99
## Type of Change
1010

11-
- [ ] Bug fix
12-
- [ ] New feature
13-
- [ ] Refactor / cleanup
14-
- [ ] Documentation
15-
- [ ] Build / CI / tooling
11+
<!--
12+
Add a release label to this PR from the Labels section of the PR sidebar
13+
(not a prefix in the PR title or commit message). It sets the release notes section and the version bump:
14+
breaking -> major
15+
feature / enhancement -> minor
16+
bug / fix -> patch
17+
chore / ci / dependencies / documentation / refactor -> patch
18+
skip-changelog -> excluded from release notes
19+
-->
1620

1721
## Checklist
1822

1923
- [ ] `just lint` passes
2024
- [ ] `just test` passes
2125
- [ ] Tests added or updated for the change
22-
- [ ] `README.md` / `CHANGELOG.md` updated if needed
26+
- [ ] `README.md` updated if needed
27+
- [ ] Release label added

‎.github/release-drafter.yml‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Release Drafter configuration.
2+
# See https://github.com/release-drafter/release-drafter for more information.
3+
name-template: 'v$RESOLVED_VERSION'
4+
tag-template: 'v$RESOLVED_VERSION'
5+
category-template: '### $TITLE'
6+
change-template: '- $TITLE (#$NUMBER) @$AUTHOR'
7+
change-title-escapes: '\<*_&@'
8+
exclude-labels:
9+
- 'skip-changelog'
10+
categories:
11+
- title: 'Breaking Changes'
12+
labels: ['breaking']
13+
- title: 'Features'
14+
labels: ['feature', 'enhancement']
15+
- title: 'Bug Fixes'
16+
labels: ['bug', 'fix']
17+
- title: 'Maintenance'
18+
labels: ['chore', 'ci', 'dependencies', 'documentation', 'refactor']
19+
version-resolver:
20+
major:
21+
labels: ['breaking']
22+
minor:
23+
labels: ['feature', 'enhancement']
24+
patch:
25+
labels: ['bug', 'fix', 'chore', 'ci', 'dependencies', 'documentation', 'refactor']
26+
default: patch
27+
autolabeler:
28+
- label: 'feature'
29+
branch: ['/^feat(ure)?\/.+/']
30+
- label: 'bug'
31+
branch: ['/^(bug)?fix\/.+/']
32+
- label: 'chore'
33+
branch: ['/^chore\/.+/']
34+
- label: 'ci'
35+
branch: ['/^ci\/.+/']
36+
files: ['.github/workflows/*']
37+
- label: 'documentation'
38+
branch: ['/^docs?\/.+/']
39+
files: ['*.md']
40+
- label: 'refactor'
41+
branch: ['/^refactor\/.+/']
42+
- label: 'dependencies'
43+
files: ['uv.lock']
44+
template: |
45+
$CHANGES
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Release Drafter
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
types: [ opened, reopened, synchronize, labeled, unlabeled ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
update-draft:
14+
if: github.event_name == 'push'
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
steps:
19+
- uses: release-drafter/release-drafter@v6
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
23+
autolabel:
24+
if: github.event_name == 'pull_request' && github.event.action != 'labeled' && github.event.action != 'unlabeled'
25+
runs-on: ubuntu-latest
26+
permissions:
27+
pull-requests: write
28+
steps:
29+
- uses: release-drafter/release-drafter@v6
30+
with:
31+
disable-releaser: true
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
35+
require-label:
36+
needs: [ autolabel ]
37+
# Run even when autolabel is skipped (labeled/unlabeled events)
38+
if: ${{ always() && github.event_name == 'pull_request' }}
39+
runs-on: ubuntu-latest
40+
permissions:
41+
pull-requests: read
42+
steps:
43+
- uses: mheap/github-action-required-labels@v5
44+
with:
45+
mode: minimum
46+
count: 1
47+
labels: "breaking, feature, enhancement, bug, fix, chore, ci, dependencies, documentation, refactor, skip-changelog"
48+
use_api: true

‎.github/workflows/release.yml‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
6+
concurrency:
7+
group: release
8+
cancel-in-progress: false
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
release:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
steps:
19+
- uses: actions/checkout@v7
20+
with:
21+
ref: main
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v7
24+
with:
25+
version: ">=0.11,<0.12"
26+
27+
- name: Refresh draft release
28+
id: drafter
29+
uses: release-drafter/release-drafter@v6
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Bump version
34+
env:
35+
VERSION: ${{ steps.drafter.outputs.resolved_version }}
36+
run: uv version "$VERSION"
37+
38+
- name: Update CHANGELOG.md
39+
uses: stefanzweifel/changelog-updater-action@v1
40+
with:
41+
latest-version: ${{ steps.drafter.outputs.tag_name }}
42+
release-notes: ${{ steps.drafter.outputs.body }}
43+
44+
- name: Commit and push
45+
id: commit
46+
env:
47+
TAG: ${{ steps.drafter.outputs.tag_name }}
48+
run: |
49+
git config user.name "github-actions[bot]"
50+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
51+
git add pyproject.toml uv.lock CHANGELOG.md
52+
git commit -m "Release $TAG"
53+
git push origin main
54+
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
55+
56+
- name: Publish release
57+
env:
58+
GH_TOKEN: ${{ github.token }}
59+
RELEASE_ID: ${{ steps.drafter.outputs.id }}
60+
SHA: ${{ steps.commit.outputs.sha }}
61+
run: |
62+
gh api -X PATCH "repos/${{ github.repository }}/releases/$RELEASE_ID" \
63+
-F draft=false -f target_commitish="$SHA"
64+
65+
- name: Build and upload artifacts
66+
env:
67+
GH_TOKEN: ${{ github.token }}
68+
TAG: ${{ steps.drafter.outputs.tag_name }}
69+
run: |
70+
uv build
71+
gh release upload "$TAG" dist/*

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6+
Release notes are generated from labeled pull requests by Release Drafter.
7+
8+
## [Unreleased]

‎README.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,32 @@ Note: Project uses `uv` and `just` to manage project configuration and commands
3434
* `just git-leaks` - scan staged changes for secrets with gitleaks
3535
* `uv add {package}` - install a dependency
3636

37+
## Releases
38+
39+
Releases are managed with [Release Drafter](https://github.com/release-drafter/release-drafter),
40+
which reads the **release labels** on merged pull requests.
41+
42+
A release label is a GitHub label added to the pull request itself, from the **Labels** section
43+
of the PR sidebar. Release Drafter only reads these labels. Commit messages and PR titles are not
44+
parsed, so prefixes like `feat:` or `fix:` have no effect. Only the labels below count as release
45+
labels; other repository labels (e.g. `good first issue`, `question`) are ignored.
46+
47+
| Release label | Version bump | Release notes section |
48+
| ----------------------------------------------------------------- | ------------ | --------------------- |
49+
| `breaking` | major | Breaking Changes |
50+
| `feature`, `enhancement` | minor | Features |
51+
| `bug`, `fix` | patch | Bug Fixes |
52+
| `chore`, `ci`, `dependencies`, `documentation`, `refactor` | patch | Maintenance |
53+
| `skip-changelog` | none | Excluded |
54+
55+
* Every PR must have at least one release label, or the `Release Drafter / require-label` check fails. If a release
56+
has PRs with different labels, the largest bump wins
57+
* Release labels are added automatically from the PR's branch name prefix (`feat/`, `fix/`, `chore/`,
58+
`ci/`, `docs/`, `refactor/`) and from the files it changes. You can add or change them by hand
59+
* Merging to `main` updates a draft GitHub Release with the next version and notes
60+
* To release, run the **Release** workflow from the Actions tab. It bumps the version in
61+
`pyproject.toml`/`uv.lock`, updates `CHANGELOG.md`, tags the release, and uploads build artifacts
62+
3763
## Usage
3864

3965
* Usage Notes

0 commit comments

Comments
 (0)