|
| 1 | +name: Release |
| 2 | + |
| 3 | +# Builds abi3 wheels (one per platform, any Python >= 3.9) and an sdist, tests each |
| 4 | +# wheel, and publishes to PyPI when a version tag is pushed. |
| 5 | +# |
| 6 | +# - pull requests touching packaging: build + test only, nothing is published |
| 7 | +# - workflow_dispatch: same, on demand |
| 8 | +# - tag vX.Y.Z (must match the version in Cargo.toml): build, test, publish |
| 9 | + |
| 10 | +on: |
| 11 | + push: |
| 12 | + tags: ["v*"] |
| 13 | + pull_request: |
| 14 | + paths: |
| 15 | + - .github/workflows/release.yml |
| 16 | + - pyproject.toml |
| 17 | + - Cargo.toml |
| 18 | + - Cargo.lock |
| 19 | + workflow_dispatch: |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: read |
| 23 | + |
| 24 | +jobs: |
| 25 | + wheels: |
| 26 | + name: wheel ${{ matrix.platform.name }} |
| 27 | + runs-on: ${{ matrix.platform.runner }} |
| 28 | + strategy: |
| 29 | + fail-fast: false |
| 30 | + matrix: |
| 31 | + platform: |
| 32 | + - { name: linux-x86_64, runner: ubuntu-latest, target: x86_64, manylinux: "2_28", test: true } |
| 33 | + - { name: linux-aarch64, runner: ubuntu-24.04-arm, target: aarch64, manylinux: "2_28", test: true } |
| 34 | + - { name: macos-arm64, runner: macos-14, target: aarch64-apple-darwin, test: true } |
| 35 | + # cross-compiled on the arm64 runner, so it can't be run here |
| 36 | + - { name: macos-x86_64, runner: macos-14, target: x86_64-apple-darwin, test: false } |
| 37 | + - { name: windows-x86_64, runner: windows-latest, target: x64, test: true } |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - uses: actions/setup-python@v5 |
| 42 | + with: |
| 43 | + python-version: "3.12" |
| 44 | + |
| 45 | + - name: Build wheel |
| 46 | + uses: PyO3/maturin-action@v1 |
| 47 | + with: |
| 48 | + target: ${{ matrix.platform.target }} |
| 49 | + manylinux: ${{ matrix.platform.manylinux || 'auto' }} |
| 50 | + args: --release --locked --out dist |
| 51 | + |
| 52 | + # the abi3 wheel is tested on the oldest and newest supported Pythons |
| 53 | + - uses: actions/setup-python@v5 |
| 54 | + id: py-oldest |
| 55 | + if: matrix.platform.test |
| 56 | + with: |
| 57 | + python-version: "3.9" |
| 58 | + |
| 59 | + - uses: actions/setup-python@v5 |
| 60 | + id: py-newest |
| 61 | + if: matrix.platform.test |
| 62 | + with: |
| 63 | + python-version: "3.13" |
| 64 | + |
| 65 | + # runs from outside the repo so the installed wheel is imported, not the source tree |
| 66 | + - name: Test wheel |
| 67 | + if: matrix.platform.test |
| 68 | + shell: bash |
| 69 | + env: |
| 70 | + PYTHONS: ${{ steps.py-oldest.outputs.python-path }};${{ steps.py-newest.outputs.python-path }} |
| 71 | + run: | |
| 72 | + IFS=';' read -ra pythons <<< "$PYTHONS" |
| 73 | + for py in "${pythons[@]}"; do |
| 74 | + echo "::group::$py" |
| 75 | + venv="$RUNNER_TEMP/venv-$("$py" -c 'import sys; print("%d%d" % sys.version_info[:2])')" |
| 76 | + "$py" -m venv "$venv" |
| 77 | + bin="$venv/bin"; [ "$RUNNER_OS" = "Windows" ] && bin="$venv/Scripts" |
| 78 | + "$bin/python" -m pip install -q dist/*.whl onnx onnxruntime |
| 79 | + cd "$RUNNER_TEMP" |
| 80 | + "$bin/python" -c "import sys, burn_python as b; print(sys.version, b.__version__, b.available_backends())" |
| 81 | + "$bin/python" "$GITHUB_WORKSPACE/tests/test_ops.py" |
| 82 | + cd "$GITHUB_WORKSPACE" |
| 83 | + echo "::endgroup::" |
| 84 | + done |
| 85 | +
|
| 86 | + - uses: actions/upload-artifact@v4 |
| 87 | + with: |
| 88 | + name: wheel-${{ matrix.platform.name }} |
| 89 | + path: dist/*.whl |
| 90 | + |
| 91 | + sdist: |
| 92 | + name: sdist |
| 93 | + runs-on: ubuntu-latest |
| 94 | + steps: |
| 95 | + - uses: actions/checkout@v4 |
| 96 | + |
| 97 | + - name: Build sdist |
| 98 | + uses: PyO3/maturin-action@v1 |
| 99 | + with: |
| 100 | + command: sdist |
| 101 | + args: --out dist |
| 102 | + |
| 103 | + - uses: actions/upload-artifact@v4 |
| 104 | + with: |
| 105 | + name: sdist |
| 106 | + path: dist/*.tar.gz |
| 107 | + |
| 108 | + publish: |
| 109 | + name: publish to PyPI |
| 110 | + if: startsWith(github.ref, 'refs/tags/v') |
| 111 | + needs: [wheels, sdist] |
| 112 | + runs-on: ubuntu-latest |
| 113 | + # PyPI trusted publishing: no API token, PyPI trusts this workflow + environment |
| 114 | + environment: |
| 115 | + name: pypi |
| 116 | + url: https://pypi.org/p/burn-python |
| 117 | + permissions: |
| 118 | + id-token: write |
| 119 | + steps: |
| 120 | + - uses: actions/checkout@v4 |
| 121 | + |
| 122 | + - name: Check tag matches Cargo.toml version |
| 123 | + run: | |
| 124 | + version=$(grep -m1 '^version' Cargo.toml | cut -d'"' -f2) |
| 125 | + if [ "v$version" != "$GITHUB_REF_NAME" ]; then |
| 126 | + echo "::error::tag $GITHUB_REF_NAME does not match Cargo.toml version $version" |
| 127 | + exit 1 |
| 128 | + fi |
| 129 | +
|
| 130 | + - uses: actions/download-artifact@v4 |
| 131 | + with: |
| 132 | + path: dist |
| 133 | + merge-multiple: true |
| 134 | + |
| 135 | + - run: ls -la dist |
| 136 | + |
| 137 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments