|
| 1 | +name: Wheels |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened, labeled, synchronize] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + release: |
| 9 | + description: 'Push wheels to pypi' |
| 10 | + type: boolean |
| 11 | + default: false |
| 12 | + required: true |
| 13 | + |
| 14 | +permissions: {} |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + py-wheels-matrix: |
| 22 | + name: "generate build matrix" |
| 23 | + runs-on: ubuntu-latest |
| 24 | + if: > |
| 25 | + github.event_name == 'workflow_dispatch' || |
| 26 | + ( |
| 27 | + github.event_name == 'pull_request' && |
| 28 | + github.event.type == 'labeled' && |
| 29 | + github.event.label.name == 'check-wheels' |
| 30 | + ) || |
| 31 | + ( |
| 32 | + github.event_name == 'pull_request' && |
| 33 | + github.event.type != 'labeled' && |
| 34 | + contains(github.event.pull_request.labels.*.name, 'check-wheels') |
| 35 | + ) |
| 36 | + outputs: |
| 37 | + matrix: ${{ steps.make-matrix.outputs.matrix }} |
| 38 | + steps: |
| 39 | + - id: make-matrix |
| 40 | + shell: python |
| 41 | + name: generate matrix |
| 42 | + run: | |
| 43 | + import itertools |
| 44 | + import json |
| 45 | + import os |
| 46 | + import pprint |
| 47 | +
|
| 48 | + builder = { |
| 49 | + ('linux', 'x86_64'): 'ubuntu-latest', |
| 50 | + ('linux', 'aarch64'): 'ubuntu-24.04-arm', |
| 51 | + ('musllinux', 'x86_64'): 'ubuntu-latest', |
| 52 | + ('musllinux', 'aarch64'): 'ubuntu-24.04-arm', |
| 53 | + ('macos', 'x86_64'): 'macos-15-intel', |
| 54 | + ('macos', 'aarch64'): 'macos-latest', |
| 55 | + ('windows', 'x86_64'): 'windows-latest', |
| 56 | + ('windows', 'aarch64'): 'windows-11-arm', |
| 57 | + } |
| 58 | +
|
| 59 | + matrix = [ |
| 60 | + d |
| 61 | + for d in map(dict, itertools.product( |
| 62 | + (('python-version', v) for v in ["3.x", "3.14t", "pypy-3.11", "graalpy-25"]), |
| 63 | + (('arch', a) for a in ["x86_64", "aarch64"]), |
| 64 | + (('platform', p) for p in ["linux", "musllinux", "windows", "macos"]) |
| 65 | + )) |
| 66 | + # on windows, only cpython has arm builds (?) |
| 67 | + if d['python-version'].startswith('3.') \ |
| 68 | + or d['platform'] != 'windows' \ |
| 69 | + or d['arch'] != 'aarch64' |
| 70 | + ] |
| 71 | + for job in matrix: |
| 72 | + match job['platform']: |
| 73 | + case 'linux': |
| 74 | + job['manylinux'] = 'auto' |
| 75 | + job['args'] = ' --zig' |
| 76 | + case 'mussllinux': |
| 77 | + job['manylinux'] = 'musllinux_1_2' |
| 78 | +
|
| 79 | + job['runs'] = builder[job['platform'], job['arch']] |
| 80 | +
|
| 81 | + with open(os.environ['GITHUB_OUTPUT'], 'w') as f: |
| 82 | + f.write("matrix=") |
| 83 | + json.dump({'include': matrix}, f) |
| 84 | + f.flush() |
| 85 | +
|
| 86 | + py-release-wheels: |
| 87 | + needs: [py-wheels-matrix] |
| 88 | + strategy: |
| 89 | + matrix: ${{fromJson(needs.py-wheels-matrix.outputs.matrix)}} |
| 90 | + |
| 91 | + runs-on: ${{ matrix.runs }} |
| 92 | + |
| 93 | + steps: |
| 94 | + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # 6.0.1 |
| 95 | + with: |
| 96 | + persist-credentials: false |
| 97 | + - uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # 6.1.0 |
| 98 | + with: |
| 99 | + python-version: ${{ matrix.python-version }} |
| 100 | + # windows/arm doesn't have a rust toolchain by default |
| 101 | + - if: matrix.platform == 'windows' && matrix.arch == 'aarch64' |
| 102 | + uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 # 1.12.0 |
| 103 | + - name: Build wheels |
| 104 | + uses: PyO3/maturin-action@04ac600d27cdf7a9a280dadf7147097c42b757ad # 1.50.1 |
| 105 | + with: |
| 106 | + args: --release --out dist -m ua-parser-rs/Cargo.toml -i python ${{ matrix.args }} |
| 107 | + sccache: 'true' |
| 108 | + manylinux: ${{ matrix.manylinux }} |
| 109 | + - name: Upload wheels |
| 110 | + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # 7.0.0 |
| 111 | + with: |
| 112 | + name: ua-parser-rs-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.python-version }} |
| 113 | + path: dist/* |
| 114 | + retention-days: 1 |
| 115 | + compression-level: 0 |
| 116 | + |
| 117 | + py-release-sdist: |
| 118 | + runs-on: ubuntu-latest |
| 119 | + steps: |
| 120 | + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # 6.0.1 |
| 121 | + with: |
| 122 | + persist-credentials: false |
| 123 | + - name: Build sdist |
| 124 | + uses: PyO3/maturin-action@04ac600d27cdf7a9a280dadf7147097c42b757ad # 1.50.1 |
| 125 | + with: |
| 126 | + command: sdist |
| 127 | + args: --out dist -m ua-parser-rs/Cargo.toml |
| 128 | + - name: Upload sdist |
| 129 | + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # 7.0.0 |
| 130 | + with: |
| 131 | + name: wheels-sdist |
| 132 | + path: dist |
| 133 | + |
| 134 | + py-release-tests: |
| 135 | + needs: py-release-wheels |
| 136 | + |
| 137 | + strategy: |
| 138 | + matrix: |
| 139 | + python-version: |
| 140 | + - "3.10" |
| 141 | + - "3.11" |
| 142 | + - "3.12" |
| 143 | + - "3.13" |
| 144 | + - "3.14" |
| 145 | + - "3.14t" |
| 146 | + - "pypy-3.11" |
| 147 | + - "graalpy-25" |
| 148 | + platform: |
| 149 | + - linux |
| 150 | + # probably requires a custom image of some sort |
| 151 | + # - musllinux |
| 152 | + - windows |
| 153 | + - macos |
| 154 | + arch: |
| 155 | + - x86_64 |
| 156 | + - aarch64 |
| 157 | + |
| 158 | + exclude: |
| 159 | + - platform: windows |
| 160 | + python-version: 3.10 |
| 161 | + arch: aarch64 |
| 162 | + - platform: windows |
| 163 | + arch: aarch64 |
| 164 | + python-version: pypy-3.11 |
| 165 | + - platform: windows |
| 166 | + python-version: graalpy-25 |
| 167 | + |
| 168 | + include: |
| 169 | + - wheel: "3.x" |
| 170 | + - python-version: "3.14t" |
| 171 | + wheel: "3.14t" |
| 172 | + - python-version: "pypy-3.11" |
| 173 | + wheel: "pypy-3.11" |
| 174 | + - python-version: "graalpy-25" |
| 175 | + wheel: "graalpy-25" |
| 176 | + |
| 177 | + - runner: ubuntu-latest |
| 178 | + - arch: aarch64 |
| 179 | + runner: ubuntu-24.04-arm |
| 180 | + - platform: windows |
| 181 | + runner: windows-latest |
| 182 | + - platform: windows |
| 183 | + arch: aarch64 |
| 184 | + runner: windows-11-arm |
| 185 | + - platform: macos |
| 186 | + runner: macos-latest |
| 187 | + - platform: macos |
| 188 | + arch: x86_64 |
| 189 | + runner: macos-15-intel |
| 190 | + - opts: "" |
| 191 | + - python-version: graalpy-25 |
| 192 | + opts: "--experimental-options --engine.CompileOnly='~tregex re'" |
| 193 | + |
| 194 | + runs-on: ${{ matrix.runner }} |
| 195 | + |
| 196 | + steps: |
| 197 | + - name: Checkout working copy |
| 198 | + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # 6.0.1 |
| 199 | + with: |
| 200 | + submodules: true |
| 201 | + persist-credentials: false |
| 202 | + - name: Set up Python ${{ matrix.python-version }} |
| 203 | + uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # 6.1.0 |
| 204 | + with: |
| 205 | + python-version: ${{ matrix.python-version }} |
| 206 | + allow-prereleases: true |
| 207 | + - name: Retrieve wheel |
| 208 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # 8.0.1 |
| 209 | + with: |
| 210 | + name: ua-parser-rs-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.wheel }} |
| 211 | + path: dist |
| 212 | + - name: Update pip |
| 213 | + run: python -mpip install --upgrade pip |
| 214 | + - name: Maybe install libyaml-dev |
| 215 | + if: startsWith(matrix.runs, 'ubuntu-latest') |
| 216 | + run: | |
| 217 | + # if binary wheels are not available for the current |
| 218 | + # package install libyaml-dev so we can install pyyaml |
| 219 | + # from source |
| 220 | + if ! pip download --only-binary :all: pyyaml > /dev/null 2>&1; then |
| 221 | + sudo apt install libyaml-dev |
| 222 | + fi |
| 223 | + - name: Install test dependencies |
| 224 | + run: python -mpip install pytest pyyaml pytest-error-for-skips |
| 225 | + - name: Install wheel |
| 226 | + run: python -mpip install --only-binary ':all:' --no-index --find-links dist ua_parser_rs |
| 227 | + - name: Install package |
| 228 | + run: python -mpip install . |
| 229 | + - name: Run tests |
| 230 | + run: python ${{ matrix.opts }} -m pytest -v -Werror -Wignore::ImportWarning --doctest-glob="*.rst" -ra --error-for-skips -k '(-regex)' |
| 231 | + |
| 232 | + py-release: |
| 233 | + name: Release |
| 234 | + runs-on: ubuntu-latest |
| 235 | + needs: [py-release-tests, py-release-sdist] |
| 236 | + if: github.event.name == 'workflow_dispatch' |
| 237 | + permissions: |
| 238 | + id-token: write |
| 239 | + environment: release |
| 240 | + steps: |
| 241 | + - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # 8.0.1 |
| 242 | + with: |
| 243 | + path: dist/ |
| 244 | + merge-multiple: true # dump every wheel file in the same directory |
| 245 | + - name: Publish to PyPI |
| 246 | + if: (inputs.release) |
| 247 | + uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # 1.13.0 |
| 248 | + with: |
| 249 | + verbose: true |
| 250 | + - name: Publish to TestPyPI |
| 251 | + if: (!inputs.release) |
| 252 | + uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # 1.13.0 |
| 253 | + with: |
| 254 | + repository-url: https://test.pypi.org/legacy/ |
| 255 | + skip-existing: true |
| 256 | + verbose: true |
0 commit comments