name: Python wheels
on:
workflow_dispatch:
push:
tags: ["v*"]
permissions:
contents: write
jobs:
preflight:
name: Comprobar tag y versión Python
runs-on: ubuntu-latest
outputs:
publish: ${{ steps.version.outputs.publish }}
steps:
- uses: actions/checkout@v4
- id: version
name: Comparar tag con python/Cargo.toml
shell: bash
run: |
set -euo pipefail
if [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
echo "Ejecución manual: se construyen los wheels."
exit 0
fi
tag="${GITHUB_REF_NAME#v}"
version="$(sed -n 's/^version = "\([^"]*\)"/\1/p' python/Cargo.toml | head -n 1)"
if [ -z "$version" ]; then
echo "::error::No se pudo leer la versión de python/Cargo.toml."
exit 1
fi
if [ "$tag" != "$version" ]; then
echo "publish=false" >> "$GITHUB_OUTPUT"
echo "::notice::El tag ${GITHUB_REF_NAME} no coincide con Python ${version}; se omiten los wheels."
exit 0
fi
echo "publish=true" >> "$GITHUB_OUTPUT"
echo "Tag ${GITHUB_REF_NAME} coincide con Python ${version}."
linux:
name: Wheel (${{ matrix.plataforma }})
needs: preflight
if: needs.preflight.outputs.publish == 'true'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
plataforma: linux-x64
imagen: quay.io/pypa/manylinux2014_x86_64:latest
- os: ubuntu-24.04-arm
plataforma: linux-arm64
imagen: quay.io/pypa/manylinux2014_aarch64:latest
steps:
- uses: actions/checkout@v4
- name: Construir manylinux2014
run: |
docker run --rm -v "$PWD:/io" -w /io \
${{ matrix.imagen }} \
bash -c '
set -euo pipefail
curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
. "$HOME/.cargo/env"
/opt/python/cp310-cp310/bin/python -m pip install --upgrade pip "maturin==1.16.0"
/opt/python/cp310-cp310/bin/python -m maturin build --release --out /io/dist --compatibility manylinux2014 --manifest-path /io/python/Cargo.toml
'
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.plataforma }}
path: dist/*.whl
wheels:
name: Wheel (${{ matrix.plataforma }})
needs: preflight
if: needs.preflight.outputs.publish == 'true'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
plataforma: windows-x64
- os: windows-11-arm
plataforma: windows-arm64
- os: macos-15-intel
plataforma: macos-intel
- os: macos-latest
plataforma: macos-arm64
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
args: --release --out dist --compatibility pypi --manifest-path python/Cargo.toml
manylinux: auto
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.plataforma }}
path: dist/*.whl
sdist:
name: Sdist
needs: preflight
if: needs.preflight.outputs.publish == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist --manifest-path python/Cargo.toml
- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz
release:
name: Adjuntar al release
needs: [preflight, wheels, linux, sdist]
if: startsWith(github.ref, 'refs/tags/') && needs.preflight.outputs.publish == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- uses: softprops/action-gh-release@v2
with:
files: dist/*