name: Release-plz release
on:
push:
branches:
- main
jobs:
release:
name: Release
runs-on: ubuntu-latest
if: "contains(github.event.head_commit.message, 'chore: release')"
environment: Rust Push
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.GIT_TOKEN || secrets.GITHUB_TOKEN }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Get version from Cargo.toml
id: version
run: |
VERSION=$(grep -oE '^version\s*=\s*"[0-9]+\.[0-9]+\.[0-9]+"' Cargo.toml | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
if [ -z "$VERSION" ]; then
echo "::error::No version found in Cargo.toml"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create and push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"
- name: Create GitHub release
run: gh release create "v${{ steps.version.outputs.version }}" --generate-notes
env:
GH_TOKEN: ${{ secrets.GIT_TOKEN || secrets.GITHUB_TOKEN }}
- name: Publish to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
build-wheels:
name: Build wheel (${{ matrix.python-version }})
runs-on: ubuntu-latest
needs: release
if: "contains(github.event.head_commit.message, 'chore: release')"
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install maturin
run: pip install maturin
- name: Sync version to pyproject.toml
run: |
VERSION=$(awk '/^\[package\]/{p=1;next} /^\[/{p=0} p && /^version\s*=\s*"/{gsub(/^version\s*=\s*"|"\s*$/,""); print; exit}' Cargo.toml)
if [ -z "$VERSION" ] || ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Invalid or missing version in Cargo.toml [package] section (got: '${VERSION}')"
exit 1
fi
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml
if ! grep -q "^version = \"$VERSION\"" pyproject.toml; then
echo "::error::Failed to sync version to pyproject.toml"
exit 1
fi
- name: Build wheel
run: maturin build --release --features pyo3
- name: Build sdist
if: matrix.python-version == '3.10'
run: maturin build --sdist
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.python-version }}
path: target/wheels/
publish-pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: build-wheels
if: "contains(github.event.head_commit.message, 'chore: release')"
environment: Pypi push
steps:
- name: Download wheels
uses: actions/download-artifact@v4
with:
pattern: wheel-*
path: all-wheels
- name: Merge wheels and sdist
run: |
mkdir -p target/wheels
find all-wheels -name "*.whl" -exec cp {} target/wheels/ \;
find all-wheels -name "*.tar.gz" -exec cp {} target/wheels/ \;
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
packages-dir: target/wheels