|
| 1 | +name: Build and upload to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: # run on request (no need for PR) |
| 5 | + release: |
| 6 | + types: [published] |
| 7 | + |
| 8 | +jobs: |
| 9 | + build_wheels: |
| 10 | + name: Build wheels |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v3 |
| 15 | + - name: Build wheels |
| 16 | + |
| 17 | + - uses: actions/upload-artifact@v3 |
| 18 | + with: |
| 19 | + path: ./wheelhouse/*.whl |
| 20 | + |
| 21 | + build_sdist: |
| 22 | + name: Build source distribution |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v3 |
| 27 | + - name: Set up Python 3.10 |
| 28 | + uses: actions/setup-python@v3 |
| 29 | + with: |
| 30 | + python-version: "3.10" |
| 31 | + - name: Install pypa/build |
| 32 | + run: python -m pip install build |
| 33 | + - name: Build sdist |
| 34 | + run: python -m build --sdist |
| 35 | + - uses: actions/upload-artifact@v3 |
| 36 | + with: |
| 37 | + path: dist/*.tar.gz |
| 38 | + |
| 39 | + publish_package: |
| 40 | + name: Publish package |
| 41 | + needs: [build_wheels, build_sdist] |
| 42 | + environment: pypi |
| 43 | + runs-on: ubuntu-latest |
| 44 | + permissions: write-all |
| 45 | + steps: |
| 46 | + - name: Download artifacts |
| 47 | + uses: actions/download-artifact@v3 |
| 48 | + with: |
| 49 | + # unpacks default artifact into dist/ |
| 50 | + # if `name: artifact` is omitted, the action will create extra parent dir |
| 51 | + name: artifact |
| 52 | + path: dist |
| 53 | + # to determine where to publish the source distribution to PyPI or TestPyPI |
| 54 | + - name: Check tag |
| 55 | + id: check-tag |
| 56 | + uses: actions-ecosystem/action-regex-match@v2 |
| 57 | + with: |
| 58 | + text: ${{ github.ref }} |
| 59 | + regex: '^refs/tags/[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+rc[0-9]+|rc[0-9]+)?$' |
| 60 | + - name: Upload package distributions to github |
| 61 | + if: ${{ steps.check-tag.outputs.match != '' }} |
| 62 | + uses: svenstaro/upload-release-action@v2 |
| 63 | + with: |
| 64 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + file: dist/* |
| 66 | + tag: ${{ github.ref }} |
| 67 | + overwrite: true |
| 68 | + file_glob: true |
| 69 | + - name: Publish package distributions to PyPI |
| 70 | + if: ${{ steps.check-tag.outputs.match != '' }} |
| 71 | + |
| 72 | + with: |
| 73 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 74 | + - name: Publish package distributions to TestPyPI |
| 75 | + if: ${{ steps.check-tag.outputs.match == '' }} |
| 76 | + |
| 77 | + with: |
| 78 | + password: ${{ secrets.TESTPYPI_API_TOKEN }} |
| 79 | + repository-url: https://test.pypi.org/legacy/ |
| 80 | + verbose: true |
0 commit comments