name: release-python
on:
push:
tags: ["v*"]
workflow_dispatch:
permissions:
contents: read
jobs:
verify-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
- name: check Cargo, Python, and tag versions agree
shell: bash
run: |
cargo_version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')"
python_version="$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")"
test "$cargo_version" = "$python_version" || { echo "::error::Cargo $cargo_version != Python $python_version"; exit 1; }
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
tag="${GITHUB_REF_NAME#v}"
test "$tag" = "$cargo_version" || { echo "::error::tag $tag != package $cargo_version"; exit 1; }
fi
linux:
needs: verify-version
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: build wheel (${{ matrix.target }})
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
manylinux: auto
args: --release --locked --out dist
- uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.target }}
path: dist
windows:
needs: verify-version
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
target: [x64]
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: "3.x"
architecture: ${{ matrix.target }}
- name: build wheel (${{ matrix.target }})
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --locked --out dist
- uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.target }}
path: dist
macos:
needs: verify-version
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: build wheel (${{ matrix.target }})
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --locked --out dist
- uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.target }}
path: dist
sdist:
needs: verify-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist
release:
name: publish to PyPI
runs-on: ubuntu-latest
needs: [linux, windows, macos, sdist]
if: startsWith(github.ref, 'refs/tags/')
permissions:
id-token: write steps:
- uses: actions/download-artifact@v4
with:
pattern: wheels-*
merge-multiple: true
path: dist
- name: publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist