Skip to content

Commit b9246a6

Browse files
abrichrclaude
andcommitted
ci: switch to python-semantic-release for automated versioning
Replaces manual commit parsing with python-semantic-release: - Automatic version bumping based on conventional commits - feat: -> minor, fix:/perf: -> patch - Creates GitHub releases automatically - Publishes to PyPI on release Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c3b3eb8 commit b9246a6

File tree

3 files changed

+35
-107
lines changed

3 files changed

+35
-107
lines changed

.github/workflows/publish.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 24 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,48 @@
1-
name: Auto Release
1+
name: Release and PyPI Publish
22

33
on:
44
push:
55
branches:
66
- main
7-
paths:
8-
- '**.py'
9-
- 'pyproject.toml'
107

118
jobs:
129
release:
13-
name: Bump version and release
1410
runs-on: ubuntu-latest
15-
# Only run on merged PRs (not direct pushes or version bump commits)
16-
if: |
17-
github.event.head_commit.message != '' &&
18-
!startsWith(github.event.head_commit.message, 'chore: bump version')
11+
concurrency: release
1912
permissions:
13+
id-token: write
2014
contents: write
2115

2216
steps:
23-
- uses: actions/checkout@v4
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
2419
with:
2520
fetch-depth: 0
26-
token: ${{ secrets.GITHUB_TOKEN }}
2721

2822
- name: Set up Python
2923
uses: actions/setup-python@v5
3024
with:
31-
python-version: "3.12"
25+
python-version: '3.12'
3226

33-
- name: Install toml
34-
run: pip install toml
27+
- name: Install uv
28+
uses: astral-sh/setup-uv@v4
3529

36-
- name: Determine version bump type
37-
id: bump-type
38-
run: |
39-
COMMIT_MSG="${{ github.event.head_commit.message }}"
40-
# Extract the type from conventional commit (feat, fix, etc.)
41-
if [[ "$COMMIT_MSG" =~ ^feat ]]; then
42-
echo "type=minor" >> $GITHUB_OUTPUT
43-
elif [[ "$COMMIT_MSG" =~ ^(fix|perf) ]]; then
44-
echo "type=patch" >> $GITHUB_OUTPUT
45-
elif [[ "$COMMIT_MSG" =~ ^(docs|style|refactor|test|chore|ci|build) ]]; then
46-
echo "type=patch" >> $GITHUB_OUTPUT
47-
else
48-
# Default to patch for non-conventional commits
49-
echo "type=patch" >> $GITHUB_OUTPUT
50-
fi
51-
52-
- name: Bump version
53-
id: bump
54-
run: |
55-
python << 'EOF'
56-
import toml
57-
import os
58-
59-
# Read current version
60-
with open('pyproject.toml', 'r') as f:
61-
data = toml.load(f)
62-
63-
current = data['project']['version']
64-
major, minor, patch = map(int, current.split('.'))
65-
66-
bump_type = os.environ.get('BUMP_TYPE', 'patch')
67-
68-
if bump_type == 'major':
69-
major += 1
70-
minor = 0
71-
patch = 0
72-
elif bump_type == 'minor':
73-
minor += 1
74-
patch = 0
75-
else: # patch
76-
patch += 1
77-
78-
new_version = f"{major}.{minor}.{patch}"
79-
data['project']['version'] = new_version
80-
81-
with open('pyproject.toml', 'w') as f:
82-
toml.dump(data, f)
30+
- name: Python Semantic Release
31+
id: release
32+
uses: python-semantic-release/python-semantic-release@v9.15.2
33+
with:
34+
github_token: ${{ secrets.GITHUB_TOKEN }}
8335

84-
print(f"Bumped {current} -> {new_version}")
36+
- name: Build package
37+
if: steps.release.outputs.released == 'true'
38+
run: uv build
8539

86-
# Set output
87-
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
88-
f.write(f"version={new_version}\n")
89-
f.write(f"tag=v{new_version}\n")
90-
EOF
91-
env:
92-
BUMP_TYPE: ${{ steps.bump-type.outputs.type }}
40+
- name: Publish to PyPI
41+
if: steps.release.outputs.released == 'true'
42+
uses: pypa/gh-action-pypi-publish@release/v1
9343

94-
- name: Commit and tag
95-
run: |
96-
git config user.name "github-actions[bot]"
97-
git config user.email "github-actions[bot]@users.noreply.github.com"
98-
git add pyproject.toml
99-
git commit -m "chore: bump version to ${{ steps.bump.outputs.version }}"
100-
git tag ${{ steps.bump.outputs.tag }}
101-
git push origin main --tags
44+
- name: Publish to GitHub Releases
45+
if: steps.release.outputs.released == 'true'
46+
uses: python-semantic-release/publish-action@v9.15.2
47+
with:
48+
github_token: ${{ secrets.GITHUB_TOKEN }}

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ testpaths = ["tests"]
9292
python_files = ["test_*.py"]
9393
asyncio_mode = "auto"
9494

95+
[tool.semantic_release]
96+
version_toml = ["pyproject.toml:project.version"]
97+
branch = "main"
98+
commit_message = "chore: release {version}"
99+
build_command = "uv build"
100+
101+
[tool.semantic_release.commit_parser_options]
102+
allowed_tags = ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"]
103+
minor_tags = ["feat"]
104+
patch_tags = ["fix", "perf"]
105+
95106
[dependency-groups]
96107
dev = [
97108
"matplotlib>=3.10.8",

0 commit comments

Comments
 (0)