|
| 1 | +name: Create library release archives, create a GH release and publish PyPI wheel and sdist on tag in main branch |
| 2 | + |
| 3 | + |
| 4 | +# This is executed automatically on a tag in the main branch |
| 5 | + |
| 6 | +# Summary of the steps: |
| 7 | +# - build wheels and sdist |
| 8 | +# - upload wheels and sdist to PyPI |
| 9 | +# - create gh-release and upload wheels and dists there |
| 10 | +# TODO: smoke test wheels and sdist |
| 11 | +# TODO: add changelog to release text body |
| 12 | + |
| 13 | +# WARNING: this is designed only for packages building as pure Python wheels |
| 14 | + |
| 15 | +on: |
| 16 | + workflow_dispatch: |
| 17 | + push: |
| 18 | + tags: |
| 19 | + - "v*.*.*" |
| 20 | + |
| 21 | +jobs: |
| 22 | + build-pypi-distribs: |
| 23 | + name: Build and publish library to PyPI |
| 24 | + runs-on: ubuntu-24.04 |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 29 | + with: |
| 30 | + persist-credentials: false # do not keep the token around |
| 31 | + |
| 32 | + - name: Set up Python 3.12 |
| 33 | + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 34 | + with: |
| 35 | + python-version: 3.12 |
| 36 | + |
| 37 | + - name: Install pypa/build and twine |
| 38 | + run: python -m pip install --user build twine |
| 39 | + |
| 40 | + - name: Build a binary wheel and a source tarball |
| 41 | + run: python -m build --sdist --wheel --outdir dist/ |
| 42 | + |
| 43 | + - name: Validate wheel and sdis for Pypi |
| 44 | + run: python -m twine check dist/* |
| 45 | + |
| 46 | + - name: Upload built archives |
| 47 | + uses: actions/upload-artifact@v4 |
| 48 | + with: |
| 49 | + name: pypi_archives |
| 50 | + path: dist/* |
| 51 | + |
| 52 | + |
| 53 | + create-gh-release: |
| 54 | + name: Create GH release |
| 55 | + needs: |
| 56 | + - build-pypi-distribs |
| 57 | + runs-on: ubuntu-24.04 |
| 58 | + |
| 59 | + steps: |
| 60 | + - name: Download built archives |
| 61 | + uses: actions/download-artifact@v4 |
| 62 | + with: |
| 63 | + name: pypi_archives |
| 64 | + path: dist |
| 65 | + |
| 66 | + - name: Create GH release |
| 67 | + uses: softprops/action-gh-release@v2 |
| 68 | + with: |
| 69 | + draft: true |
| 70 | + files: dist/* |
| 71 | + |
| 72 | + |
| 73 | + create-pypi-release: |
| 74 | + name: Create PyPI release |
| 75 | + needs: |
| 76 | + - create-gh-release |
| 77 | + runs-on: ubuntu-24.04 |
| 78 | + environment: pypi-publish |
| 79 | + permissions: |
| 80 | + id-token: write |
| 81 | + |
| 82 | + steps: |
| 83 | + - name: Download built archives |
| 84 | + uses: actions/download-artifact@v4 |
| 85 | + with: |
| 86 | + name: pypi_archives |
| 87 | + path: dist |
| 88 | + |
| 89 | + - name: Publish to PyPI |
| 90 | + if: startsWith(github.ref, 'refs/tags') |
| 91 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments