| 1 |
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
branches: |
| 6 |
- releases/* |
| 7 |
tags: |
| 8 |
- v* |
| 9 |
|
| 10 |
jobs: |
| 11 |
build_wheels: |
| 12 |
name: Build wheels on ${{ matrix.platform }} |
| 13 |
runs-on: ${{ matrix.platform }} |
| 14 |
strategy: |
| 15 |
matrix: |
| 16 |
platform: [ubuntu-latest, macos-latest, windows-latest, ubuntu-24.04-arm, windows-11-arm] |
| 17 |
env: |
| 18 |
CIBW_ARCHS_LINUX: "native" |
| 19 |
CIBW_ARCHS_MACOS: "x86_64 universal2 arm64" |
| 20 |
|
| 21 |
CIBW_PRERELEASE_PYTHONS: True |
| 22 |
CIBW_SKIP: "pp*" |
| 23 |
steps: |
| 24 |
- name: Checkout 🛎️ |
| 25 |
uses: actions/checkout@v4 |
| 26 |
with: |
| 27 |
fetch-depth: 20 |
| 28 |
- name: Fetch release tags |
| 29 |
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
| 30 |
- name: Set up Python 🐍 |
| 31 |
uses: actions/setup-python@v6 |
| 32 |
with: |
| 33 |
python-version: 3.13 |
| 34 |
- name: Install cibuildwheel |
| 35 |
run: | |
| 36 |
python -m pip install -U pip cibuildwheel |
| 37 |
- name: Build wheels |
| 38 |
run: python -m cibuildwheel --output-dir wheelhouse |
| 39 |
- name: Upload wheels |
| 40 |
uses: actions/upload-artifact@v4 |
| 41 |
with: |
| 42 |
name: artifact-${{ matrix.platform }} |
| 43 |
path: wheelhouse/*.whl |
| 44 |
|
| 45 |
build_source_dist: |
| 46 |
name: Build source dist |
| 47 |
runs-on: ubuntu-latest |
| 48 |
steps: |
| 49 |
- name: Checkout 🛎️ |
| 50 |
uses: actions/checkout@v4 |
| 51 |
with: |
| 52 |
fetch-depth: 20 |
| 53 |
- name: Fetch release tags |
| 54 |
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
| 55 |
- name: Set up Python 🐍 |
| 56 |
uses: actions/setup-python@v4 |
| 57 |
with: |
| 58 |
python-version: 3.13 |
| 59 |
- name: Build source distribution & wheels🎡 |
| 60 |
run: | |
| 61 |
python -m pip install -U pip setuptools setuptools_scm[toml] build |
| 62 |
python -m build --sdist |
| 63 |
- name: Upload source distribution |
| 64 |
uses: actions/upload-artifact@v4 |
| 65 |
with: |
| 66 |
name: artifact-source |
| 67 |
path: dist/*.tar.gz |
| 68 |
|
| 69 |
pypi-publish: |
| 70 |
name: publish Python 🐍 distributions 📦 to PyPI and TestPyPI |
| 71 |
runs-on: ubuntu-latest |
| 72 |
needs: [build_wheels, build_source_dist] |
| 73 |
environment: pypi |
| 74 |
permissions: |
| 75 |
id-token: write |
| 76 |
steps: |
| 77 |
- name: download dist artifacts |
| 78 |
uses: actions/download-artifact@v4 |
| 79 |
with: |
| 80 |
path: dist |
| 81 |
merge-multiple: true |
| 82 |
- name: Publish distribution 📦 to Test PyPI |
| 83 |
if: ${{ startsWith(github.event.ref, 'refs/heads/releases') }} |
| 84 |
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc |
| 85 |
with: |
| 86 |
repository-url: https://test.pypi.org/legacy/ |
| 87 |
- name: Publish distribution 📦 to PyPI |
| 88 |
if: startsWith(github.event.ref, 'refs/tags') |
| 89 |
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc |