|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + name: 🏗️ Build Package |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + version: ${{ steps.check-version.outputs.version }} |
| 14 | + package_name: ${{ steps.check-version.outputs.package_name }} |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v6 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: ⚡ Install uv |
| 21 | + uses: astral-sh/setup-uv@v7 |
| 22 | + with: |
| 23 | + enable-cache: true |
| 24 | + |
| 25 | + - name: 🐍 Set up Python |
| 26 | + uses: actions/setup-python@v6 |
| 27 | + with: |
| 28 | + python-version-file: "pyproject.toml" |
| 29 | + |
| 30 | + - name: 📦 Build package |
| 31 | + run: uv build |
| 32 | + |
| 33 | + - name: ✅ Check tag version match |
| 34 | + id: check-version |
| 35 | + run: | |
| 36 | + VERSION=$(grep -m 1 '^version = ' pyproject.toml | cut -d '"' -f 2) |
| 37 | + NAME=$(grep -m 1 '^name = ' pyproject.toml | cut -d '"' -f 2) |
| 38 | + TAG=${GITHUB_REF#refs/tags/v} |
| 39 | + echo "Found version: $VERSION" |
| 40 | + echo "Found package name: $NAME" |
| 41 | + echo "Found tag: $TAG" |
| 42 | + if [ "$VERSION" != "$TAG" ]; then |
| 43 | + echo "::error::Version in pyproject.toml ($VERSION) does not match tag ($TAG)" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 47 | + echo "package_name=$NAME" >> $GITHUB_OUTPUT |
| 48 | +
|
| 49 | + - name: 📤 Upload Build Artifacts |
| 50 | + uses: actions/upload-artifact@v6 |
| 51 | + with: |
| 52 | + name: python-package-distributions |
| 53 | + path: dist/ |
| 54 | + |
| 55 | + publish-pypi: |
| 56 | + name: 🚀 Publish to PyPI |
| 57 | + needs: build |
| 58 | + runs-on: ubuntu-latest |
| 59 | + environment: |
| 60 | + name: release |
| 61 | + url: https://pypi.org/project/${{ needs.build.outputs.package_name }} |
| 62 | + permissions: |
| 63 | + id-token: write |
| 64 | + steps: |
| 65 | + - name: 📥 Download Artifacts |
| 66 | + uses: actions/download-artifact@v7 |
| 67 | + with: |
| 68 | + name: python-package-distributions |
| 69 | + path: dist/ |
| 70 | + |
| 71 | + - name: 📤 Publish to PyPI |
| 72 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 73 | + with: |
| 74 | + skip-existing: true |
| 75 | + |
| 76 | + github-release: |
| 77 | + name: 📝 Create GitHub Release |
| 78 | + needs: [build, publish-pypi] |
| 79 | + runs-on: ubuntu-latest |
| 80 | + permissions: |
| 81 | + contents: write |
| 82 | + steps: |
| 83 | + - name: 📥 Download Artifacts |
| 84 | + uses: actions/download-artifact@v7 |
| 85 | + with: |
| 86 | + name: python-package-distributions |
| 87 | + path: dist/ |
| 88 | + |
| 89 | + - name: 🚀 Create GitHub Release |
| 90 | + uses: softprops/action-gh-release@v2 |
| 91 | + with: |
| 92 | + files: dist/* |
| 93 | + generate_release_notes: true |
| 94 | + name: v${{ needs.build.outputs.version }} |
| 95 | + body: | |
| 96 | + ## ${{ needs.build.outputs.package_name }} v${{ needs.build.outputs.version }} |
| 97 | +
|
| 98 | + Install via PyPI: |
| 99 | + ```bash |
| 100 | + pip install ${{ needs.build.outputs.package_name }}==${{ needs.build.outputs.version }} |
| 101 | + ``` |
| 102 | +
|
| 103 | + Or via [uv](https://docs.astral.sh/uv/): |
| 104 | + ```bash |
| 105 | + uv tool install ${{ needs.build.outputs.package_name }}@${{ needs.build.outputs.version }} |
| 106 | + ``` |
0 commit comments