|
| 1 | +name: Release (TestPyPI only) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + id-token: write |
| 11 | + packages: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + name: Build distributions |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - uses: actions/setup-python@v5 |
| 20 | + with: |
| 21 | + python-version: '3.12' |
| 22 | + cache: 'pip' |
| 23 | + - name: Install build tooling |
| 24 | + run: | |
| 25 | + python -m pip install -U pip build twine |
| 26 | + - name: Build sdist/wheel |
| 27 | + run: | |
| 28 | + python -m build |
| 29 | + python -m twine check dist/* |
| 30 | + - name: Upload artifact |
| 31 | + uses: actions/upload-artifact@v4 |
| 32 | + with: |
| 33 | + name: dist |
| 34 | + path: dist/* |
| 35 | + |
| 36 | + publish-testpypi: |
| 37 | + name: Publish to TestPyPI |
| 38 | + needs: [build] |
| 39 | + runs-on: ubuntu-latest |
| 40 | + if: contains(github.ref_name, '-') |
| 41 | + steps: |
| 42 | + - uses: actions/download-artifact@v4 |
| 43 | + with: |
| 44 | + name: dist |
| 45 | + path: dist |
| 46 | + - name: Publish to TestPyPI |
| 47 | + |
| 48 | + with: |
| 49 | + repository-url: https://test.pypi.org/legacy/ |
| 50 | + verbose: true |
| 51 | + env: |
| 52 | + PYPI_API_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }} |
| 53 | + |
| 54 | + publish-pypi: |
| 55 | + name: Publish to PyPI |
| 56 | + needs: [build] |
| 57 | + runs-on: ubuntu-latest |
| 58 | + if: ${{ !contains(github.ref_name, '-') }} |
| 59 | + steps: |
| 60 | + - uses: actions/download-artifact@v4 |
| 61 | + with: |
| 62 | + name: dist |
| 63 | + path: dist |
| 64 | + - name: Publish to PyPI |
| 65 | + |
| 66 | + with: |
| 67 | + verbose: true |
| 68 | + env: |
| 69 | + PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} |
| 70 | + |
| 71 | + github-release: |
| 72 | + name: Create GitHub Release |
| 73 | + # depend on both publish jobs so we can inspect their outcome |
| 74 | + needs: [publish-testpypi, publish-pypi] |
| 75 | + runs-on: ubuntu-latest |
| 76 | + # only run when the relevant publish job succeeded for the tag type: |
| 77 | + if: >- |
| 78 | + (contains(github.ref_name, '-') && needs.publish-testpypi.result == 'success') || |
| 79 | + (!contains(github.ref_name, '-') && needs.publish-pypi.result == 'success') |
| 80 | + steps: |
| 81 | + - uses: actions/download-artifact@v4 |
| 82 | + with: |
| 83 | + name: dist |
| 84 | + path: dist |
| 85 | + - name: Create Release |
| 86 | + uses: softprops/action-gh-release@v2 |
| 87 | + with: |
| 88 | + tag_name: ${{ github.ref_name }} |
| 89 | + name: ${{ github.ref_name }} |
| 90 | + body: | |
| 91 | + Automated release for ${{ github.ref_name }}. |
| 92 | + draft: false |
| 93 | + prerelease: ${{ contains(github.ref_name, '-') }} |
| 94 | + files: | |
| 95 | + dist/*.whl |
| 96 | + dist/*.tar.gz |
0 commit comments