Add publish and release workflows #16
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: cd | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- '**' | |
pull_request: | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
build: | |
name: build on ${{ matrix.os }} (${{ matrix.target }}${{ matrix.os == 'linux' && format(' - {0}', matrix.manylinux == 'auto' && 'manylinux' || matrix.manylinux) || '' }}) | |
# only run on push to main and on release | |
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Full Build') | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [linux, macos, windows] | |
target: [x86_64, aarch64] | |
manylinux: ['2_28'] | |
include: | |
# manylinux for various platforms | |
- { os: linux, manylinux: '2_28', target: x86_64 } | |
#- { os: linux, manylinux: '2_28', target: i686 } | |
- { os: linux, manylinux: '2_28', target: aarch64 } | |
- { os: linux, manylinux: '2_28', target: armv7 } | |
- { os: linux, manylinux: '2_28', target: ppc64le } | |
#- { os: linux, manylinux: '2_28', target: s390x } | |
# musl | |
- { os: linux, manylinux: musllinux_1_1, target: x86_64 } | |
- { os: linux, manylinux: musllinux_1_1, target: aarch64 } | |
- { os: linux, manylinux: musllinux_1_1, target: armv7 } | |
# macos | |
- { os: macos, target: x86_64 } | |
- { os: macos, target: aarch64 } | |
# windows | |
- { os: windows, target: x86_64 } | |
- { os: windows, target: i686, python-architecture: x86 } | |
- { os: windows, target: aarch64 } | |
runs-on: ${{ (matrix.os == 'linux' && 'ubuntu') || matrix.os }}-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.13' | |
architecture: ${{ matrix.python-architecture || 'x64' }} | |
- run: pip install twine | |
- uses: PyO3/maturin-action@v1 | |
with: | |
target: ${{ matrix.target }} | |
manylinux: ${{ matrix.manylinux }} | |
args: --release --out dist --interpreter '3.11 3.12 3.13' | |
rust-toolchain: stable | |
docker-options: -e CI | |
before-script-linux: | | |
# If we're running on rhel centos, install needed packages. | |
if command -v yum &> /dev/null; then | |
yum update -y && yum install -y perl-core | |
fi | |
- run: ${{ (matrix.os == 'windows' && 'dir') || 'ls -lh' }} dist/ | |
- run: twine check --strict dist/* | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: pypi-wheels-${{ matrix.os }}-${{ matrix.target }}-${{ matrix.manylinux }} | |
path: dist | |
inspect: | |
needs: build | |
outputs: | |
version: ${{ steps.version.outcome == 'success' && steps.version.outputs.full || '0.0.0' }} | |
prerelease: ${{ steps.version.outcome == 'success' && steps.version.outputs.prerelease || '' }} | |
runs-on: ubuntu-latest | |
steps: | |
# keep this the same as below in `publish` | |
- uses: actions/download-artifact@v4 | |
with: | |
pattern: pypi-wheels-* | |
merge-multiple: true | |
path: dist/ | |
- run: ls -lh dist/ | |
- id: version | |
uses: release-kit/semver@v2 | |
continue-on-error: true # continue if tag doesn’t match | |
with: | |
fallback: '0.0.0' # fall back if there is no tag | |
# TODO: some more checks? `twine` is already run above | |
publish: | |
if: needs.inspect.outputs.version != '0.0.0' | |
runs-on: ubuntu-latest | |
needs: inspect | |
environment: pypi | |
permissions: | |
id-token: write # to authenticate as Trusted Publisher to pypi.org | |
steps: | |
# keep this the same as above in `inspect` | |
- uses: actions/download-artifact@v4 | |
with: | |
pattern: pypi-wheels-* | |
merge-multiple: true | |
path: dist/ | |
- uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
packages-dir: dist/ | |
- uses: ncipollo/release-action@v1 | |
with: | |
name: ${{ needs.inspect.outputs.version }} | |
prerelease: ${{ needs.inspect.outputs.prerelease != '' }} |