Add pytest-benchmark GitHub Actions workflow (#82)
#179
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 and publish wheels | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*.*.*' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| env: | |
| RUST_VERSION: "1.90.0" | |
| jobs: | |
| build: | |
| name: Build on ${{ matrix.os }} (${{ matrix.target }} - ${{ matrix.manylinux || 'auto' }}) | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ ubuntu, macos, windows ] | |
| target: [ x86_64, aarch64 ] | |
| manylinux: [ auto ] | |
| include: | |
| # not PGO optimized: | |
| - os: windows | |
| target: x86_64 | |
| interpreter: pypy3.11 | |
| - os: windows | |
| target: i686 | |
| python-architecture: x86 | |
| interpreter: 3.8 3.9 3.10 3.11 3.12 3.13 3.14 | |
| - os: windows | |
| target: aarch64 | |
| interpreter: 3.11 3.12 3.13 3.14 | |
| - os: macos | |
| target: x86_64 | |
| interpreter: pypy3.11 | |
| - os: macos | |
| target: aarch64 | |
| # actions/setup-python@v5 does not support 3.8 and 3.9 on arm64 | |
| interpreter: 3.8 3.9 pypy3.11 | |
| - os: ubuntu | |
| target: x86_64 | |
| interpreter: pypy3.11 | |
| - os: ubuntu | |
| target: i686 | |
| - os: ubuntu | |
| target: aarch64 | |
| - os: ubuntu | |
| target: armv7 | |
| interpreter: 3.8 3.9 3.10 3.11 3.12 3.13 3.14 | |
| - os: ubuntu | |
| target: ppc64le | |
| interpreter: 3.8 3.9 3.10 3.11 3.12 3.13 3.14 | |
| - os: ubuntu | |
| target: s390x | |
| interpreter: 3.8 3.9 3.10 3.11 3.12 3.13 3.14 | |
| - os: ubuntu | |
| target: x86_64 | |
| manylinux: musllinux_1_1 | |
| - os: ubuntu | |
| target: aarch64 | |
| manylinux: musllinux_1_1 | |
| exclude: | |
| # Windows on arm64 only supports Python 3.11+ | |
| - os: windows | |
| target: aarch64 | |
| runs-on: ${{ matrix.os }}-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| architecture: ${{ matrix.python-architecture || 'x64' }} | |
| - name: Install rust | |
| id: rust-toolchain | |
| uses: dtolnay/rust-toolchain@master | |
| with: | |
| components: llvm-tools | |
| toolchain: ${{ env.RUST_VERSION }} | |
| - name: Build wheels | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| target: ${{ matrix.target }} | |
| manylinux: ${{ matrix.manylinux || 'auto' }} | |
| args: --release --out dist --interpreter ${{ matrix.interpreter || '3.8 3.9 3.10 3.11 3.12 3.13 3.14 pypy3.11' }} | |
| rust-toolchain: ${{ env.RUST_VERSION }} | |
| docker-options: -e CI | |
| - name: List wheels. | |
| run: ${{ (runner.os == 'Windows' && 'dir') || 'ls -lh' }} dist/ | |
| - name: Upload wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pypi_wheels_${{ matrix.os }}_${{ matrix.target }}_${{ matrix.interpreter || 'all' }}_${{ matrix.manylinux }} | |
| path: dist | |
| build-pgo: | |
| name: PGO build on ${{ matrix.os }} / ${{ matrix.interpreter }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ ubuntu-latest, windows-latest, macos-13, macos-14 ] | |
| interpreter: [ '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14'] | |
| exclude: | |
| # actions/setup-python@v5 does not support 3.8 and 3.9 on arm64 | |
| - os: macos-14 | |
| interpreter: '3.8' | |
| - os: macos-14 | |
| interpreter: '3.9' | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Set Git to use LF. | |
| run: | | |
| git config --global core.autocrlf false | |
| git config --global core.eol lf | |
| - name: Checkout repository. | |
| uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 # required for macos-13 with Python 3.8-3.10... otherwise UV uses PyPy... | |
| with: | |
| python-version: ${{ matrix.interpreter }} | |
| - name: Install UV. | |
| uses: astral-sh/setup-uv@v6 | |
| with: | |
| python-version: ${{ matrix.interpreter }} | |
| - name: Install rust. | |
| id: rust-toolchain | |
| uses: dtolnay/rust-toolchain@master | |
| with: | |
| components: llvm-tools | |
| toolchain: ${{ env.RUST_VERSION }} | |
| - name: Set RUST_HOST. | |
| shell: bash | |
| run: echo RUST_HOST=$(rustc -Vv | grep host | cut -d ' ' -f 2) >> "$GITHUB_ENV" | |
| - name: Build wheel with profile generation. | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| manylinux: auto | |
| args: --release --out pgo-wheel --interpreter ${{ matrix.interpreter }} | |
| rust-toolchain: ${{ env.RUST_VERSION }} | |
| docker-options: -e CI | |
| env: | |
| RUSTFLAGS: "-Cprofile-generate=${{ github.workspace }}/profdata" | |
| - name: Gather PGO data. | |
| run: | | |
| uv sync --group testing | |
| uv pip install libipld --no-index --no-deps --find-links pgo-wheel --force-reinstall | |
| uv run pytest . --benchmark-enable | |
| # we can't use github.workspace here because of Windows with backslashes | |
| rustup run ${{ env.RUST_VERSION }} bash -c 'echo LLVM_PROFDATA=$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/${{ env.RUST_HOST }}/bin/llvm-profdata >> "$GITHUB_ENV"' | |
| - name: Prepare merged PGO data. | |
| run: ${{ env.LLVM_PROFDATA }} merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata | |
| - name: Build PGO-optimized wheel. | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| manylinux: auto | |
| args: --release --out dist --interpreter ${{ matrix.interpreter }} | |
| rust-toolchain: ${{ env.RUST_VERSION }} | |
| docker-options: -e CI | |
| env: | |
| RUSTFLAGS: "-Cprofile-use=${{ github.workspace }}/merged.profdata" | |
| - name: List wheels. | |
| run: ${{ (runner.os == 'Windows' && 'dir') || 'ls -lh' }} dist/ | |
| - name: Upload wheels. | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pypi_pgo_wheels_${{ matrix.os }}_${{ matrix.interpreter }} | |
| path: dist | |
| build-sdist: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Build sdist. | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| command: sdist | |
| args: --out dist | |
| - name: Upload sdist. | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pypi_sdist | |
| path: dist | |
| check: | |
| needs: [ build, build-pgo, build-sdist ] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.14' | |
| - name: Get dist artifacts. | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: pypi_* | |
| merge-multiple: true | |
| path: dist | |
| - name: List dist files. | |
| run: | | |
| ls -lh dist/ | |
| ls -l dist/ | |
| echo "`ls dist | wc -l` files" | |
| - name: Check wheels. | |
| run: | | |
| pip install -U twine | |
| twine check --strict dist/* | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| if: "startsWith(github.ref, 'refs/tags/')" | |
| needs: [ build, build-pgo, build-sdist, check ] | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| pattern: pypi_* | |
| merge-multiple: true | |
| path: dist | |
| - name: Publish to PyPI | |
| uses: PyO3/maturin-action@v1 | |
| env: | |
| MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} | |
| with: | |
| command: upload | |
| args: --non-interactive --skip-existing dist/* |