Build & publish ben-py wheels #14
This file contains hidden or 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: Build & publish ben-py wheels | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| upload_to: | |
| description: "Upload destination for manual runs" | |
| type: choice | |
| required: true | |
| default: "testpypi" | |
| options: [testpypi, pypi] | |
| env: | |
| PKG_DIR: ben-py | |
| OUT_DIR: dist | |
| permissions: | |
| contents: read | |
| id-token: write # for PyPI/TestPyPI Trusted Publishing (OIDC) | |
| jobs: | |
| linux: | |
| name: linux (${{ matrix.target }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: [x86_64, aarch64] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Build wheels (manylinux_2_28, abi3) | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| target: ${{ matrix.target }} | |
| manylinux: "2_28" | |
| working-directory: ${{ env.PKG_DIR }} | |
| command: build | |
| args: >- | |
| --release | |
| --locked | |
| --out ${{ env.OUT_DIR }} | |
| # Smoke-test the built wheel in a clean venv before it can be published. aarch64 wheels are | |
| # cross-built and cannot execute on this runner, so only the native target is smoked. | |
| - name: Smoke test wheel | |
| if: matrix.target == 'x86_64' | |
| run: | | |
| python3 -m venv /tmp/wheel-smoke | |
| /tmp/wheel-smoke/bin/pip install ${{ env.PKG_DIR }}/${{ env.OUT_DIR }}/*.whl | |
| /tmp/wheel-smoke/bin/python .github/workflows/wheel_smoke.py | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: wheels-linux-${{ matrix.target }} | |
| path: ${{ env.PKG_DIR }}/${{ env.OUT_DIR }}/* | |
| if-no-files-found: error | |
| macos: | |
| name: macos (universal2, abi3) | |
| runs-on: macos-14 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Python 3.11+ | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.11" | |
| - name: Add x86_64 target | |
| run: rustup target add x86_64-apple-darwin | |
| - name: Build universal2 wheel | |
| uses: PyO3/maturin-action@v1 | |
| env: | |
| MACOSX_DEPLOYMENT_TARGET: "10.13" | |
| with: | |
| manylinux: "off" | |
| working-directory: ${{ env.PKG_DIR }} | |
| command: build | |
| args: >- | |
| --release | |
| --locked | |
| --target universal2-apple-darwin | |
| --out ${{ env.OUT_DIR }} | |
| - name: Smoke test wheel | |
| run: | | |
| python3 -m venv /tmp/wheel-smoke | |
| /tmp/wheel-smoke/bin/pip install ${{ env.PKG_DIR }}/${{ env.OUT_DIR }}/*.whl | |
| /tmp/wheel-smoke/bin/python .github/workflows/wheel_smoke.py | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: wheels-macos-universal2 | |
| path: ${{ env.PKG_DIR }}/${{ env.OUT_DIR }}/* | |
| if-no-files-found: error | |
| windows: | |
| name: windows (x64, abi3) | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| # Ensure the active interpreter satisfies abi3-py311 | |
| - name: Set up Python 3.11+ | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.11" | |
| architecture: x64 | |
| - name: Build wheel (Windows x64, abi3) | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| manylinux: "off" | |
| working-directory: ${{ env.PKG_DIR }} | |
| command: build | |
| args: >- | |
| --release | |
| --locked | |
| --out ${{ env.OUT_DIR }} | |
| - name: Smoke test wheel | |
| shell: pwsh | |
| run: | | |
| python -m venv $env:TEMP\wheel-smoke | |
| $wheel = Get-ChildItem "${{ env.PKG_DIR }}\${{ env.OUT_DIR }}\*.whl" | Select-Object -First 1 | |
| & "$env:TEMP\wheel-smoke\Scripts\pip" install $wheel.FullName | |
| & "$env:TEMP\wheel-smoke\Scripts\python" .github\workflows\wheel_smoke.py | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: wheels-windows | |
| path: ${{ env.PKG_DIR }}/${{ env.OUT_DIR }}/* | |
| if-no-files-found: error | |
| windows-arm64: | |
| name: windows (ARM64, abi3) | |
| runs-on: windows-11-arm | |
| env: | |
| PKG_DIR: ben-py | |
| OUT_DIR: dist | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Python (ARM64) | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.11" | |
| architecture: arm64 | |
| - name: Build wheel (win_arm64, abi3) | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| working-directory: ${{ env.PKG_DIR }} | |
| command: build | |
| args: >- | |
| --release | |
| --locked | |
| --out ${{ env.OUT_DIR }} | |
| --target aarch64-pc-windows-msvc | |
| - name: Smoke test wheel | |
| shell: pwsh | |
| run: | | |
| python -m venv $env:TEMP\wheel-smoke | |
| $wheel = Get-ChildItem "${{ env.PKG_DIR }}\${{ env.OUT_DIR }}\*.whl" | Select-Object -First 1 | |
| & "$env:TEMP\wheel-smoke\Scripts\pip" install $wheel.FullName | |
| & "$env:TEMP\wheel-smoke\Scripts\python" .github\workflows\wheel_smoke.py | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: wheels-windows-arm64 | |
| path: ${{ env.PKG_DIR }}/${{ env.OUT_DIR }}/* | |
| if-no-files-found: error | |
| sdist: | |
| name: sdist | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Build sdist | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| manylinux: "off" | |
| working-directory: ${{ env.PKG_DIR }} | |
| command: sdist | |
| args: >- | |
| --out ${{ env.OUT_DIR }} | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: sdist | |
| path: ${{ env.PKG_DIR }}/${{ env.OUT_DIR }}/* | |
| if-no-files-found: error | |
| publish: | |
| name: Publish | |
| needs: [linux, macos, windows, windows-arm64, sdist] | |
| runs-on: ubuntu-latest | |
| if: | | |
| startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' | |
| steps: | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| path: collected | |
| - name: Collect dists | |
| run: | | |
| mkdir -p upload | |
| find collected -type f -name "*.whl" -exec cp {} upload/ \; | |
| find collected -type f -name "*.tar.gz" -exec cp {} upload/ \; | |
| ls -l upload | |
| - name: Set repository URL (manual runs) | |
| id: repo | |
| if: ${{ github.event_name == 'workflow_dispatch' }} | |
| run: | | |
| if [ "${{ github.event.inputs.upload_to }}" = "testpypi" ]; then | |
| echo "url=https://test.pypi.org/legacy/" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "url=" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Publish (Trusted Publishing) | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: upload | |
| repository-url: ${{ steps.repo.outputs.url }} | |
| # To use an API token instead of OIDC, drop repository-url above and set: | |
| # password: ${{ secrets.PYPI_API_TOKEN }} # for PyPI | |
| # password: ${{ secrets.TEST_PYPI_API_TOKEN }} # for TestPyPI |