Wheels #111
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: Wheels | |
| on: | |
| #pull_request: | |
| workflow_dispatch: | |
| inputs: | |
| release: | |
| description: 'Push wheels to pypi' | |
| type: boolean | |
| default: false | |
| required: true | |
| permissions: | |
| contents: read | |
| jobs: | |
| py-wheels-matrix: | |
| name: "generate build matrix" | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.make-matrix.outputs.matrix }} | |
| steps: | |
| - id: make-matrix | |
| shell: python | |
| name: generate matrix | |
| run: | | |
| import itertools | |
| import json | |
| import os | |
| import pprint | |
| builder = { | |
| ('linux', 'x86_64'): 'ubuntu-latest', | |
| ('linux', 'aarch64'): 'ubuntu-24.04-arm', | |
| ('musllinux', 'x86_64'): 'ubuntu-latest', | |
| ('musllinux', 'aarch64'): 'ubuntu-24.04-arm', | |
| ('macos', 'x86_64'): 'macos-13', | |
| ('macos', 'aarch64'): 'macos-latest', | |
| ('windows', 'x86_64'): 'windows-latest', | |
| ('windows', 'aarch64'): 'windows-11-arm', | |
| } | |
| matrix = [ | |
| d | |
| for d in map(dict, itertools.product( | |
| (('python-version', v) for v in ["3.x", "pypy-3.10", "pypy-3.11", "graalpy-24"]), | |
| (('arch', a) for a in ["x86_64", "aarch64"]), | |
| (('platform', p) for p in ["linux", "musllinux", "windows", "macos"]) | |
| )) | |
| # on windows, only cpython has arm builds (?) | |
| if not ( | |
| d['platform'] == 'windows' | |
| and d['arch'] == 'aarch64' | |
| and d['python-version'] != '3.x' | |
| ) | |
| # windows and graal don't work | |
| if not (d['platform'] == 'windows' and d['python-version'] == 'graalpy-24') | |
| ] | |
| for job in matrix: | |
| match job['platform']: | |
| case 'linux': | |
| job['manylinux'] = 'auto' | |
| job['args'] = ' --zig' | |
| case 'mussllinux': | |
| job['manylinux'] = 'musllinux_1_2' | |
| job['runs'] = builder[job['platform'], job['arch']] | |
| with open(os.environ['GITHUB_OUTPUT'], 'w') as f: | |
| f.write("matrix=") | |
| json.dump({'include': matrix}, f) | |
| f.flush() | |
| py-release-wheels: | |
| needs: [py-wheels-matrix] | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{fromJson(needs.py-wheels-matrix.outputs.matrix)}} | |
| runs-on: ${{ matrix.runs }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| # windows/arm doesn't have a rust toolchain by default | |
| - if: matrix.platform == 'windows' && matrix.arch == 'aarch64' | |
| uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 # 1.12.0 | |
| - name: Build wheels | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| args: --release --out dist -m ua-parser-py/Cargo.toml -i python ${{ matrix.args }} | |
| sccache: 'true' | |
| manylinux: ${{ matrix.manylinux }} | |
| - name: Upload wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.python-version }} | |
| path: dist/* | |
| retention-days: 1 | |
| compression-level: 0 | |
| py-release-sdist: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false | |
| - name: Build sdist | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| command: sdist | |
| args: --out dist -m ua-parser-py/Cargo.toml | |
| - name: Upload sdist | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-sdist | |
| path: dist | |
| py-release-tests: | |
| needs: py-release-wheels | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: | |
| - "3.9" | |
| - "3.10" | |
| - "3.11" | |
| - "3.12" | |
| - "3.13" | |
| - "pypy-3.10" | |
| - "pypy-3.11" | |
| - "graalpy-24" | |
| platform: | |
| - linux | |
| # probably requires a custom image of some sort | |
| # - musllinux | |
| - windows | |
| - macos | |
| arch: | |
| - x86_64 | |
| - aarch64 | |
| exclude: | |
| - platform: windows | |
| arch: aarch64 | |
| python-version: 3.9 | |
| - platform: windows | |
| python-version: 3.10 | |
| arch: aarch64 | |
| - platform: windows | |
| arch: aarch64 | |
| python-version: pypy-3.10 | |
| - platform: windows | |
| arch: aarch64 | |
| python-version: pypy-3.11 | |
| - platform: windows | |
| python-version: graalpy-24 | |
| include: | |
| - wheel: "3.x" | |
| - python-version: "pypy-3.10" | |
| wheel: "pypy-3.10" | |
| - python-version: "pypy-3.11" | |
| wheel: "pypy-3.11" | |
| - python-version: "graalpy-24" | |
| wheel: "graalpy-24" | |
| - runner: ubuntu-latest | |
| - arch: aarch64 | |
| runner: ubuntu-24.04-arm | |
| - platform: windows | |
| runner: windows-latest | |
| - platform: windows | |
| arch: aarch64 | |
| runner: windows-11-arm | |
| - platform: macos | |
| runner: macos-latest | |
| - platform: macos | |
| arch: x86_64 | |
| runner: macos-13 | |
| runs-on: ${{ matrix.runner }} | |
| steps: | |
| - name: Checkout working copy | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: true | |
| persist-credentials: false | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| allow-prereleases: true | |
| - name: Retrieve wheel | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: wheels-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.wheel }} | |
| path: dist | |
| - name: Update pip | |
| run: python -mpip install --upgrade pip | |
| - name: Maybe install libyaml-dev | |
| if: startsWith(matrix.runs, 'ubuntu-latest') | |
| run: | | |
| # if binary wheels are not available for the current | |
| # package install libyaml-dev so we can install pyyaml | |
| # from source | |
| if ! pip download --only-binary :all: pyyaml > /dev/null 2>&1; then | |
| sudo apt install libyaml-dev | |
| fi | |
| - name: Install test dependencies | |
| run: python -mpip install pytest pyyaml | |
| - name: Install wheel | |
| run: python -mpip install --only-binary ':all:' --no-index --find-links dist ua_parser_rs | |
| - name: Run tests | |
| run: python -mpytest -v -Werror -ra ua-parser-py | |
| py-release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| needs: [py-release-tests, py-release-sdist] | |
| if: github.event == 'workflow_dispatch' && inputs.release | |
| permissions: | |
| # Use to sign the release artifacts | |
| id-token: write | |
| # Used to upload release artifacts | |
| contents: write | |
| # Used to generate artifact attestation | |
| attestations: write | |
| environment: release | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| - name: Generate artifact attestation | |
| uses: actions/attest-build-provenance@v1 | |
| with: | |
| subject-path: 'wheels-*/*' | |
| - name: Publish to PyPI | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| command: upload | |
| args: --non-interactive --skip-existing wheels-*/* |