Skip to content

Commit

Permalink
Update build action to "test" building on all python versions, then u…
Browse files Browse the repository at this point in the history
…pload to pyPI if successful
  • Loading branch information
LincolnPuzey committed May 29, 2024
1 parent a707e58 commit 37398f4
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Publish to PyPI"
name: "Build distributions and publish to PyPI"

on:
push:
Expand All @@ -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/

0 comments on commit 37398f4

Please sign in to comment.