|
1 |
| -name: Release library as a PyPI wheel and sdist on tag |
| 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 |
2 | 10 |
|
3 | 11 | on:
|
4 |
| - release: |
5 |
| - types: [created] |
| 12 | + workflow_dispatch: |
| 13 | + push: |
| 14 | + tags: |
| 15 | + - "v*.*.*" |
6 | 16 |
|
7 | 17 | jobs:
|
8 |
| - build-and-publish-to-pypi: |
| 18 | + build-pypi-distribs: |
9 | 19 | name: Build and publish library to PyPI
|
10 | 20 | runs-on: ubuntu-24.04
|
| 21 | + |
11 | 22 | steps:
|
12 |
| - - uses: actions/checkout@v4 |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + - name: Set up Python |
| 25 | + uses: actions/setup-python@v5 |
| 26 | + with: |
| 27 | + python-version: 3.12 |
13 | 28 |
|
14 |
| - - name: Set up Python |
15 |
| - uses: actions/setup-python@v5 |
16 |
| - with: |
17 |
| - python-version: 3.12 |
| 29 | + - name: Install pypa/build and twine |
| 30 | + run: python -m pip install --user --upgrade build twine packaging pip setuptools |
18 | 31 |
|
19 |
| - - name: Install pypa/build and twine |
20 |
| - run: python -m pip install --user --upgrade build twine packaging pip setuptools |
| 32 | + - name: Build a binary wheel and a source tarball |
| 33 | + run: python -m build --sdist --wheel --outdir dist/ |
21 | 34 |
|
22 |
| - - name: Build a binary wheel and a source tarball |
23 |
| - run: python -m build --sdist --wheel --outdir dist/ . |
| 35 | + - name: Validate wheel and sdis for Pypi |
| 36 | + run: python -m twine check dist/* |
| 37 | + |
| 38 | + - name: Upload built archives |
| 39 | + uses: actions/upload-artifact@v4 |
| 40 | + with: |
| 41 | + name: pypi_archives |
| 42 | + path: dist/* |
| 43 | + |
| 44 | + |
| 45 | + create-gh-release: |
| 46 | + name: Create GH release |
| 47 | + needs: |
| 48 | + - build-pypi-distribs |
| 49 | + runs-on: ubuntu-24.04 |
24 | 50 |
|
25 |
| - - name: Check wheel and sdist with twine |
26 |
| - run: python -m twine check dist/* |
| 51 | + steps: |
| 52 | + - name: Download built archives |
| 53 | + uses: actions/download-artifact@v4 |
| 54 | + with: |
| 55 | + name: pypi_archives |
| 56 | + path: dist |
| 57 | + |
| 58 | + - name: Create GH release |
| 59 | + uses: softprops/action-gh-release@v2 |
| 60 | + with: |
| 61 | + draft: true |
| 62 | + files: dist/* |
| 63 | + |
| 64 | + |
| 65 | + create-pypi-release: |
| 66 | + name: Create PyPI release |
| 67 | + needs: |
| 68 | + - create-gh-release |
| 69 | + runs-on: ubuntu-24.04 |
| 70 | + |
| 71 | + steps: |
| 72 | + - name: Download built archives |
| 73 | + uses: actions/download-artifact@v4 |
| 74 | + with: |
| 75 | + name: pypi_archives |
| 76 | + path: dist |
27 | 77 |
|
28 |
| - - name: Publish distribution to PyPI |
29 |
| - if: startsWith(github.ref, 'refs/tags') |
30 |
| - uses: pypa/gh-action-pypi-publish@release/v1 |
31 |
| - with: |
32 |
| - password: ${{ secrets.PYPI_API_TOKEN }} |
| 78 | + - name: Publish to PyPI |
| 79 | + if: startsWith(github.ref, 'refs/tags') |
| 80 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 81 | + with: |
| 82 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments