name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
publish-crates:
description: Publish to crates.io
type: boolean
default: true
publish-linux:
description: Publish Linux wheel to PyPI
type: boolean
default: true
publish-macos:
description: Publish macOS wheel to PyPI
type: boolean
default: true
publish-windows:
description: Publish Windows wheel to PyPI
type: boolean
default: true
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"
jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: clippy, rustfmt
- run: cargo fmt --check
- run: cargo clippy --all-features
- run: cargo doc --all-features --no-deps
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: Swatinem/rust-cache@v2
- run: cargo test --all-features
preflight:
name: Preflight
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract version from Cargo.toml
id: cargo-version
run: |
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Found Cargo.toml version: $VERSION"
- name: Verify VERSION file
run: |
CARGO_VER="${{ steps.cargo-version.outputs.version }}"
FILE_VER=$(cat VERSION | tr -d ' \n')
if [ "$CARGO_VER" != "$FILE_VER" ]; then
echo "Mismatch: Cargo.toml ($CARGO_VER) != VERSION ($FILE_VER)"
exit 1
fi
echo "VERSION file matches"
- name: Verify pyproject.toml version
run: |
CARGO_VER="${{ steps.cargo-version.outputs.version }}"
PY_VER=$(grep '^version = ' python/pyproject.toml | sed 's/version = "\(.*\)"/\1/')
if [ "$CARGO_VER" != "$PY_VER" ]; then
echo "Mismatch: Cargo.toml ($CARGO_VER) != pyproject.toml ($PY_VER)"
exit 1
fi
echo "pyproject.toml version matches"
- name: Verify CHANGELOG has entry for this version
run: |
CARGO_VER="${{ steps.cargo-version.outputs.version }}"
if ! grep -Eq "## \[$CARGO_VER\]" CHANGELOG.md; then
echo "CHANGELOG.md missing entry for version $CARGO_VER"
exit 1
fi
echo "CHANGELOG has entry for $CARGO_VER"
publish-crates:
name: Publish (crates.io)
if: github.event_name == 'workflow_dispatch' && inputs.publish-crates
needs: [check, test, preflight]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
publish-linux:
name: Publish (Linux)
if: github.event_name == 'workflow_dispatch' && inputs.publish-linux
needs: [check, test, preflight]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: x86_64-unknown-linux-gnu
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: pip install maturin
- run: maturin publish --target x86_64-unknown-linux-gnu
working-directory: python
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
publish-macos:
name: Publish (macOS)
if: github.event_name == 'workflow_dispatch' && inputs.publish-macos
needs: [check, test, preflight]
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: aarch64-apple-darwin
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: pip install maturin
- run: maturin publish --target aarch64-apple-darwin
working-directory: python
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
publish-windows:
name: Publish (Windows)
if: github.event_name == 'workflow_dispatch' && inputs.publish-windows
needs: [check, test, preflight]
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: x86_64-pc-windows-msvc
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: pip install maturin
- run: maturin publish --target x86_64-pc-windows-msvc
working-directory: python
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}