|
1 | 1 | name: Publish to PyPI |
2 | 2 |
|
3 | 3 | on: |
4 | | - release: |
5 | | - types: [published] |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # Trigger on version tags like v0.1.0, v1.2.3, etc. |
6 | 7 | workflow_dispatch: # Allow manual trigger |
7 | 8 |
|
8 | 9 | jobs: |
9 | 10 | build-and-publish: |
10 | 11 | runs-on: ubuntu-latest |
11 | 12 | permissions: |
12 | 13 | id-token: write # Required for trusted publishing |
13 | | - contents: read |
| 14 | + contents: write # Required for creating releases |
14 | 15 |
|
15 | 16 | steps: |
16 | 17 | - uses: actions/checkout@v4 |
|
23 | 24 | - name: Install uv |
24 | 25 | uses: astral-sh/setup-uv@v5 |
25 | 26 |
|
| 27 | + - name: Get version from pyproject.toml |
| 28 | + id: get_version |
| 29 | + run: | |
| 30 | + VERSION=$(uv run python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") |
| 31 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 32 | + echo "Package version: $VERSION" |
| 33 | + |
| 34 | + - name: Verify tag matches version |
| 35 | + run: | |
| 36 | + TAG_VERSION="${GITHUB_REF#refs/tags/v}" |
| 37 | + PYPROJECT_VERSION="${{ steps.get_version.outputs.version }}" |
| 38 | + if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then |
| 39 | + echo "Error: Tag version ($TAG_VERSION) does not match pyproject.toml version ($PYPROJECT_VERSION)" |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | + echo "Version check passed: $TAG_VERSION" |
| 43 | + |
26 | 44 | - name: Install build dependencies |
27 | 45 | run: uv pip install --system build twine |
28 | 46 |
|
|
32 | 50 | - name: Check package |
33 | 51 | run: twine check dist/* |
34 | 52 |
|
| 53 | + - name: Create GitHub Release |
| 54 | + uses: softprops/action-gh-release@v2 |
| 55 | + with: |
| 56 | + name: Release v${{ steps.get_version.outputs.version }} |
| 57 | + body: | |
| 58 | + Release version ${{ steps.get_version.outputs.version }} |
| 59 | + |
| 60 | + See [CHANGELOG](https://github.com/${{ github.repository }}/blob/master/CHANGELOG.md) for details. |
| 61 | + files: | |
| 62 | + dist/*.whl |
| 63 | + dist/*.tar.gz |
| 64 | + draft: false |
| 65 | + prerelease: false |
| 66 | + |
35 | 67 | - name: Publish to PyPI |
36 | 68 | uses: pypa/gh-action-pypi-publish@release/v1 |
37 | 69 | with: |
|
0 commit comments