Repository navigation
416 lines (374 loc) · 15.7 KB
/
Copy pathpython.yml
File metadata and controls
416 lines (374 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# This file evolved from being autogenerated with maturin and then **heavily
# manually** edited. You can regenerate it as below for comparative reference.
# Last time this was done was with maturin v1.12.6 at 2026-03-17.
#
# maturin generate-ci github --pytest --manifest-path bindings/py/Cargo.toml
#
name: Python (Bindings)
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash
env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
UV_HTTP_RETRIES: 5
UV_HTTP_TIMEOUT: 60
# sccache's GitHub cache entries follow the same main-only saving as
# rust-cache. maturin-action forwards SCCACHE_* into its containers.
SCCACHE_GHA_RW_MODE: ${{ github.ref == 'refs/heads/main' && 'READ_WRITE' || 'READ_ONLY' }}
jobs:
plan:
runs-on: ubuntu-slim
outputs:
test: ${{ steps.decisions.outputs.test }}
gate: ${{ steps.decisions.outputs.gate }}
steps:
- uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
if: github.event_name == 'pull_request'
id: filter
with:
filters: |
src:
- 'bindings/py/**'
- 'core/**'
- 'macros/**'
- 'sysand/**'
- 'Cargo.*'
- '.github/workflows/python.yml'
- '.github/scripts/*'
- id: decisions
run: |
test=${{ steps.filter.outputs.src == 'true' || github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
gate=${{ github.event_name == 'pull_request' }}
echo "test=$test" >> "$GITHUB_OUTPUT"
echo "gate=$gate" >> "$GITHUB_OUTPUT"
windows:
needs: [plan]
if: needs.plan.outputs.test == 'true'
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
# Two wheels cover all supported Python versions:
# - abi3 for the lowest supported version (GIL-enabled 3.10+)
# - abi3t for 3.15 (GIL-enabled and free-threaded 3.15+)
platform:
- runner: windows-latest
target: x64
rust_target: x86_64-pc-windows-msvc
python: "3.10"
abi3t: true
cargo_test: true
# Python 3.10 isn't available on the arm runners.
- runner: windows-11-arm
target: arm64 # not aarch64 because expected by setup-python
rust_target: aarch64-pc-windows-msvc
python: "3.11"
abi3t: true
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
id: python-abi3
with:
python-version: ${{ matrix.platform.python }}
architecture: ${{ matrix.platform.target }}
# The last installed Python is the default one on PATH.
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
if: matrix.platform.abi3t
with:
python-version: "3.15t"
architecture: ${{ matrix.platform.target }}
- uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
with:
enable-cache: ${{ !startsWith(github.ref, 'refs/tags/') }}
save-cache: ${{ github.ref == 'refs/heads/main' }}
# No caches on tag builds, see cache-poisoning in .github/zizmor.yml
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
with:
# A cache saved by a PR is visible only to that PR, and it evicts
# main's caches once the repository's 10GB limit is reached.
save-if: ${{ github.ref == 'refs/heads/main' }}
key: ${{ matrix.platform.runner }}
# `abi3` is enabled to test what the wheels are built with: abi3t on
# 3.15t, the default Python. The Rust tests run in one job per OS.
- name: cargo test ... (Python bindings)
if: matrix.platform.cargo_test
run: |
cd bindings/py
cargo test --locked --package sysand-py --no-default-features --features abi3,tls-aws-lc-rs --target ${{ matrix.platform.rust_target }}
# An explicit interpreter keeps maturin from also picking up 3.15t,
# which would select abi3t and build a version-specific wheel instead.
- name: Build wheels
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
with:
target: ${{ matrix.platform.rust_target }}
working-directory: bindings/py
args: --release --out ../../dist --compatibility pypi --interpreter ${{ steps.python-abi3.outputs.python-path }}
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Build abi3t wheels
if: matrix.platform.abi3t
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
with:
target: ${{ matrix.platform.rust_target }}
working-directory: bindings/py
args: --release --out ../../dist --compatibility pypi --interpreter python3.15t
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Upload wheels
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wheels-windows-${{ matrix.platform.target }}
path: dist
if-no-files-found: error
- name: pytest
run: |
export UV_PYTHON=${{ matrix.platform.python }}
export ACTIVATION_SCRIPT=.venv/Scripts/activate
.github/scripts/run-pytest.sh
- name: pytest (abi3t)
if: matrix.platform.abi3t
run: |
export UV_PYTHON=3.15t
export ACTIVATION_SCRIPT=.venv/Scripts/activate
.github/scripts/run-pytest.sh
linux:
needs: [plan]
if: needs.plan.outputs.test == 'true'
runs-on: ${{ matrix.platform.runner }}
strategy:
fail-fast: false
matrix:
platform:
- runner: ubuntu-24.04
target: x86_64
cargo_test: true
- runner: ubuntu-24.04-arm
target: aarch64
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: "3.10"
- uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
with:
enable-cache: ${{ !startsWith(github.ref, 'refs/tags/') }}
save-cache: ${{ github.ref == 'refs/heads/main' }}
# No caches on tag builds, see cache-poisoning in .github/zizmor.yml
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
with:
# A cache saved by a PR is visible only to that PR, and it evicts
# main's caches once the repository's 10GB limit is reached.
save-if: ${{ github.ref == 'refs/heads/main' }}
key: ${{ matrix.platform.runner }}
# `abi3` is enabled to test what the wheels are built with: abi3 on 3.10.
- name: cargo test ... (Python bindings)
if: matrix.platform.cargo_test
run: cargo test --locked --package sysand-py --no-default-features --features abi3,tls-aws-lc-rs
- name: Build wheels (manylinux)
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
with:
target: ${{ matrix.platform.target }}
working-directory: bindings/py
# The image also has CPython 3.15, for which maturin would pick
# abi3t and build version-specific wheels for 3.10-3.14.
args: --release --out ../../dist --compatibility pypi --interpreter python3.10
manylinux: manylinux2014
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Build wheels (musllinux)
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
with:
target: ${{ matrix.platform.target }}
working-directory: bindings/py
args: --release --out ../../dist --compatibility pypi
manylinux: musllinux_1_2
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Build abi3t wheels (manylinux)
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
with:
target: ${{ matrix.platform.target }}
working-directory: bindings/py
args: --release --out ../../dist --compatibility pypi --interpreter python3.15
manylinux: manylinux2014 # TODO: don't use default cross-compile containers for aarch64
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Build abi3t wheels (musllinux)
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
with:
target: ${{ matrix.platform.target }}
working-directory: bindings/py
args: --release --out ../../dist --compatibility pypi --interpreter python3.15
manylinux: musllinux_1_2
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Upload wheels
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist
if-no-files-found: error
- name: pytest (manylinux)
run: .github/scripts/run-pytest.sh
- name: pytest (manylinux, abi3t)
run: UV_PYTHON=3.15t .github/scripts/run-pytest.sh
- name: pytest (musllinux)
run: |
docker run \
--rm -v ${{ github.workspace }}:/io -w /io \
ghcr.io/astral-sh/uv:python3.10-alpine \
sh .github/scripts/run-pytest.sh
macos:
needs: [plan]
if: needs.plan.outputs.test == 'true'
runs-on: macos-latest
strategy:
matrix:
platform:
# Cross-compiled on the arm64 runner, so the x86_64 wheels are not
# tested.
- target: x86_64
- target: aarch64
test: true
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: "3.10"
- uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
with:
enable-cache: ${{ !startsWith(github.ref, 'refs/tags/') }}
save-cache: ${{ github.ref == 'refs/heads/main' }}
# No caches on tag builds, see cache-poisoning in .github/zizmor.yml
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
with:
# A cache saved by a PR is visible only to that PR, and it evicts
# main's caches once the repository's 10GB limit is reached.
save-if: ${{ github.ref == 'refs/heads/main' }}
key: ${{ matrix.platform.target }}
# `abi3` is enabled to test what the wheels are built with: abi3 on 3.10.
- name: cargo test ... (Python bindings)
if: matrix.platform.test
run: cargo test --locked --package sysand-py --no-default-features --features abi3,tls-aws-lc-rs
- name: Build wheels
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
with:
target: ${{ matrix.platform.target }}
working-directory: bindings/py
args: --release --out ../../dist --compatibility pypi
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Build abi3t wheels
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
with:
target: ${{ matrix.platform.target }}
working-directory: bindings/py
args: --release --out ../../dist --compatibility pypi --interpreter python3.15
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Upload wheels
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wheels-macos-${{ matrix.platform.target }}
path: dist
if-no-files-found: error
- name: pytest
if: matrix.platform.test
run: .github/scripts/run-pytest.sh
- name: pytest (abi3t)
if: matrix.platform.test
run: UV_PYTHON=3.15t .github/scripts/run-pytest.sh
sdist:
needs: [plan]
if: needs.plan.outputs.test == 'true'
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
- name: Maturin workaround
# Maturin-action blindly downloads the specified toolchain without
# checking that it won't be needed at all for sdist
# TODO: fix maturin so that this isn't needed
run: rm rust-toolchain.toml
- name: Build sdist
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
with:
command: sdist
working-directory: bindings/py
args: --out ../../dist
- name: Upload sdist
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wheels-sdist
path: dist
if-no-files-found: error
ci-gate:
name: Python CI Gate
needs: [plan, windows, linux, macos, sdist]
if: needs.plan.outputs.gate == 'true' && !cancelled()
runs-on: ubuntu-slim
steps:
- run: |
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
exit 1
fi
release:
name: Release to PyPI
environment: pypi-publish
needs: [linux, macos, windows, sdist]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-24.04
permissions:
id-token: write # for actions/attest and pypa/gh-action-pypi-publish
attestations: write # for actions/attest and pypa/gh-action-pypi-publish
artifact-metadata: write # for actions/attest
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: wheels-*
path: downloads
- name: Check and collect packages
run: |
# Any job in this run can upload artifacts, so accept exactly the
# expected set rather than whatever matches the pattern.
expected="$(printf '%s\n' \
wheels-windows-x64 \
wheels-windows-arm64 \
wheels-linux-x86_64 \
wheels-linux-aarch64 \
wheels-macos-x86_64 \
wheels-macos-aarch64 \
wheels-sdist \
| sort)"
actual="$(find downloads -mindepth 1 -maxdepth 1 -printf '%f\n' | sort)"
if [[ "$actual" != "$expected" ]]; then
echo "unexpected set of artifacts (keep in sync with the windows/linux/macos/sdist matrix):" >&2
diff <(echo "$expected") <(echo "$actual") >&2
exit 1
fi
mkdir dist
cp downloads/*/* dist/
- name: Generate artifact attestation
uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
with:
subject-path: "dist/*"
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
attestations: true