From 37398f4961fa9326ba2012b581e256d9b1b203b3 Mon Sep 17 00:00:00 2001 From: Lincoln Puzey <18750802+LincolnPuzey@users.noreply.github.com> Date: Wed, 29 May 2024 21:58:30 +0800 Subject: [PATCH] Update build action to "test" building on all python versions, then upload to pyPI if successful --- .github/workflows/publish-to-pypi.yml | 44 +++++++++++++++++++-------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 9cc5c2c..b49b5cb 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -1,4 +1,4 @@ -name: "Publish to PyPI" +name: "Build distributions and publish to PyPI" on: push: @@ -11,32 +11,50 @@ on: - cron: '30 22 15 * *' jobs: - build-and-publish: - name: Build and publish Python distributions to PyPI + build: + name: Build Python distributions runs-on: ubuntu-latest + strategy: + # Matrix to exercise the build backend on all versions of python supported + matrix: + python: ['3.8', '3.9', '3.10', '3.11', '3.12'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - name: Set up Python 3.9 - uses: actions/setup-python@v4 + - name: Set up Python + uses: actions/setup-python@v5 with: - python-version: 3.9 + python-version: ${{ matrix.python }} - name: Install pypa/build run: | pip install build + python --version pip list - name: Build a binary wheel and a source tarball run: python -m build + - uses: actions/upload-artifact@v4 + with: + name: distributions-built-with-py${{ matrix.python }} + path: dist/ + + publish: + name: "Publish to PyPI" + # Only upload for an actual tag + if: ${{ startsWith(github.ref, 'refs/tags') }} + runs-on: ubuntu-latest + needs: + - build + steps: + - uses: actions/download-artifact@v4 + with: + # Download distributions from one job of the matrix + name: "distributions-built-with-py-3.12" + path: "dist" + - name: Publish distribution to PyPI - if: startsWith(github.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.PYPI_API_TOKEN }} - - - uses: actions/upload-artifact@v3 - with: - name: pypi-packages - path: dist/