|
1 | | -name: Auto Release |
| 1 | +name: Release and PyPI Publish |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
7 | | - paths: |
8 | | - - '**.py' |
9 | | - - 'pyproject.toml' |
10 | 7 |
|
11 | 8 | jobs: |
12 | 9 | release: |
13 | | - name: Bump version and release |
14 | 10 | 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 |
19 | 12 | permissions: |
| 13 | + id-token: write |
20 | 14 | contents: write |
21 | 15 |
|
22 | 16 | steps: |
23 | | - - uses: actions/checkout@v4 |
| 17 | + - name: Checkout repository |
| 18 | + uses: actions/checkout@v4 |
24 | 19 | with: |
25 | 20 | fetch-depth: 0 |
26 | | - token: ${{ secrets.GITHUB_TOKEN }} |
27 | 21 |
|
28 | 22 | - name: Set up Python |
29 | 23 | uses: actions/setup-python@v5 |
30 | 24 | with: |
31 | | - python-version: "3.12" |
| 25 | + python-version: '3.12' |
32 | 26 |
|
33 | | - - name: Install toml |
34 | | - run: pip install toml |
| 27 | + - name: Install uv |
| 28 | + uses: astral-sh/setup-uv@v4 |
35 | 29 |
|
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 }} |
83 | 35 |
|
84 | | - print(f"Bumped {current} -> {new_version}") |
| 36 | + - name: Build package |
| 37 | + if: steps.release.outputs.released == 'true' |
| 38 | + run: uv build |
85 | 39 |
|
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 |
93 | 43 |
|
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 }} |
0 commit comments