Repository navigation
590 lines (532 loc) · 20.2 KB
/
Copy pathpublish-python.yml
File metadata and controls
590 lines (532 loc) · 20.2 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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
name: Publish Python packages to PyPI
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
publish_target:
description: "Target registry"
required: true
default: "pypi"
type: choice
options:
- pypi
concurrency:
group: publish-python-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
id-token: write
# Canonical Tier A wheel matrix: ten ordinary-CPython `cp39-abi3` wheel
# families plus one sdist (see `scripts/validate_release_artifacts.py`, which
# is the canonical validation table and must be updated together with the
# matrix below when an approved target is added or removed).
#
# Target conventions follow `maturin generate-ci` (maturin 1.14): short target
# aliases (`x86_64`, `aarch64`, `armv7`, `x64`) with an explicit `manylinux`
# policy per Linux entry. `musllinux_1_2` selects the musl wheel family.
# GNU armv7l uses the `2_28` floor: PyPA never shipped an armv7l
# manylinux2014 tag, so one must not be invented here, and maturin-action has
# no container for armv7l at `2_31` (it falls back to a host build where
# `ring` misses its cross-gcc). `2_28` is the newest floor with container
# support (`ghcr.io/rust-cross/manylinux_2_28-cross:armv7`); the validator
# accepts any real `manylinux_*_armv7l` floor.
#
# Tier B (i686/ppc64le/s390x/riscv64 GNU+musl) is deferred until Tier A is
# green: each target still needs a PyPA-image build proof, a dependency-graph
# build without feature reduction, and an executable smoke before it can join
# the required set. Free-threaded CPython (`abi3t`/version-specific `t`
# wheels) is explicitly separate and is not built here.
#
# maturin is deliberately versioned: `maturin-version` below and the pip
# `maturin==` pin in `build-sdist` must move together within the
# `maturin>=1.0,<2.0` range required by `crates/eggress-python/pyproject.toml`.
env:
MATURIN_VERSION: "v1.14.1"
jobs:
validate:
name: Validate version coherence
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Extract versions and verify coherence
shell: bash
env:
RELEASE_TAG: ${{ github.ref_type == 'tag' && github.ref_name || '' }}
run: |
set -euo pipefail
python3 - <<'PY'
import os
import re
import tomllib
from pathlib import Path
def field(path: str, *keys: str) -> str:
value = tomllib.loads(Path(path).read_text())
for key in keys:
value = value[key]
if not isinstance(value, str) or not value:
raise SystemExit(f"::error::{path} has no string field {'/'.join(keys)}")
return value
workspace = field("Cargo.toml", "workspace", "package", "version")
binding_manifest = tomllib.loads(Path("crates/eggress-python/Cargo.toml").read_text())
binding_version = binding_manifest.get("package", {}).get("version")
if isinstance(binding_version, dict):
# The binding crate inherits its version from the workspace
# (`version.workspace = true`); resolve it the same way cargo does.
if binding_version.get("workspace") is not True:
raise SystemExit("::error::crates/eggress-python/Cargo.toml package/version must be a string or workspace-inherited")
binding = workspace
elif isinstance(binding_version, str) and binding_version:
binding = binding_version
else:
raise SystemExit("::error::crates/eggress-python/Cargo.toml has no string field package/version")
project = field("crates/eggress-python/pyproject.toml", "project", "version")
versions = {"workspace": workspace, "binding": binding, "pyproject": project}
print(*[f"{name} version: {value}" for name, value in versions.items()], sep="\n")
if len(set(versions.values())) != 1:
raise SystemExit(f"::error::version mismatch: {versions}")
tag = os.environ.get("RELEASE_TAG", "")
if tag:
if not re.fullmatch(r"v[0-9]+\.[0-9]+\.[0-9]+", tag):
raise SystemExit(f"::error::production tag must be vMAJOR.MINOR.PATCH: {tag}")
expected = tag[1:]
if expected != workspace:
raise SystemExit(f"::error::tag version {expected} != workspace version {workspace}")
print(f"tag version matches: {tag}")
else:
print("manual dispatch: internal version coherence verified")
PY
build-wheels:
name: "Build wheel (${{ matrix.family }})"
needs: validate
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64
manylinux: "2014"
family: linux-x86_64-gnu
- os: ubuntu-24.04-arm
target: aarch64
manylinux: "2014"
family: linux-aarch64-gnu
- os: ubuntu-latest
target: armv7
manylinux: "2_28"
family: linux-armv7l-gnu
- os: ubuntu-latest
target: x86_64
manylinux: musllinux_1_2
family: linux-x86_64-musl
- os: ubuntu-24.04-arm
target: aarch64
manylinux: musllinux_1_2
family: linux-aarch64-musl
- os: ubuntu-latest
target: armv7
manylinux: musllinux_1_2
family: linux-armv7l-musl
- os: macos-15-intel
target: x86_64
family: macos-x86_64
- os: macos-14
target: aarch64
family: macos-arm64
- os: windows-latest
target: x64
family: windows-x86_64
- os: windows-11-arm
target: aarch64
family: windows-arm64
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Setup QEMU
if: runner.os == 'Linux' && matrix.target == 'armv7'
uses: docker/setup-qemu-action@v3
with:
platforms: arm
- name: Build wheel
uses: PyO3/maturin-action@v1
with:
command: build
args: --release --locked --out dist -m crates/eggress-python/Cargo.toml
target: ${{ matrix.target }}
manylinux: ${{ matrix.manylinux || 'auto' }}
maturin-version: ${{ env.MATURIN_VERSION }}
- name: List artifacts
shell: bash
run: ls -la dist/
- uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.family }}
path: dist/*.whl
build-sdist:
name: Build source distribution
needs: validate
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build tools
run: python -m pip install --upgrade pip "maturin==1.14.1"
- name: Build sdist
run: maturin sdist --out dist -m crates/eggress-python/Cargo.toml
- name: Verify sdist contents
shell: bash
run: |
set -euo pipefail
SDIST=$(ls dist/*.tar.gz)
echo "Built sdist: ${SDIST}"
# List via a file: `tar ... | head` trips pipefail with SIGPIPE.
tar tzf "${SDIST}" > sdist_contents.txt
wc -l sdist_contents.txt
head -30 sdist_contents.txt
echo "sdist built successfully (clean-install smoke validates contents)"
- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz
collect-artifacts:
name: Collect and validate artifacts
needs: [build-wheels, build-sdist]
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: wheel-*
path: dist/
merge-multiple: true
- uses: actions/download-artifact@v4
with:
name: sdist
path: dist/
- name: Validate artifact set
shell: bash
run: |
set -euo pipefail
echo "=== All artifacts ==="
ls -la dist/
python -m pip install --upgrade pip "packaging>=24"
python3 scripts/validate_release_artifacts.py
- uses: actions/upload-artifact@v4
with:
name: release-artifacts
path: dist/
smoke-test:
name: "Smoke test (${{ matrix.os }})"
needs: collect-artifacts
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
- os: ubuntu-24.04-arm
- os: macos-15-intel
- os: macos-14
- os: windows-latest
- os: windows-11-arm
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: release-artifacts
path: dist/
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Find matching wheel
id: find-wheel
shell: bash
run: |
set -euo pipefail
PLATFORM=$(python -c "import sys, platform; print(platform.system().lower())")
ARCH=$(python -c "import platform; print(platform.machine().lower())")
echo "Platform: ${PLATFORM} ${ARCH}"
WHEEL=""
for whl in dist/*.whl; do
NAME=$(basename "${whl}")
case "${PLATFORM}" in
linux)
# GNU wheels only here; musllinux has its own smoke job.
# ("musllinux" contains no "manylinux" substring.)
if echo "${NAME}" | grep -q "manylinux" && echo "${NAME}" | grep -q "${ARCH}"; then
WHEEL="${whl}"
break
fi
;;
darwin)
if echo "${NAME}" | grep -q "macosx"; then
if [[ "${ARCH}" == "arm64" ]] && echo "${NAME}" | grep -q "arm64"; then
WHEEL="${whl}"
break
elif [[ "${ARCH}" == "x86_64" ]] && echo "${NAME}" | grep -q "x86_64"; then
WHEEL="${whl}"
break
fi
fi
;;
windows)
if [[ "${ARCH}" == "arm64" ]]; then
if echo "${NAME}" | grep -q "win_arm64"; then
WHEEL="${whl}"
break
fi
elif echo "${NAME}" | grep -q "win_amd64"; then
WHEEL="${whl}"
break
fi
;;
esac
done
if [[ -z "${WHEEL}" ]]; then
echo "::error::No matching wheel found for ${PLATFORM} ${ARCH}"
ls dist/*.whl
exit 1
fi
echo "Found wheel: $(basename ${WHEEL})"
echo "wheel_path=${WHEEL}" >> "$GITHUB_OUTPUT"
- name: Install and smoke test
shell: bash
run: |
set -euo pipefail
python -m venv .venv-test
if [[ "$RUNNER_OS" == "Windows" ]]; then
.venv-test/Scripts/python.exe -m pip install --upgrade pip
.venv-test/Scripts/python.exe -m pip install "${{ steps.find-wheel.outputs.wheel_path }}"
.venv-test/Scripts/python.exe -m pip install --no-deps ./python-pproxy-compat
.venv-test/Scripts/python.exe scripts/release_artifact_smoke.py
echo "=== target evidence ==="
.venv-test/Scripts/python.exe -c "import platform, sys; print('machine:', platform.machine()); print(sys.version); print('libc:', platform.libc_ver())"
echo "wheel: ${{ steps.find-wheel.outputs.wheel_path }}"
else
.venv-test/bin/python -m pip install --upgrade pip
.venv-test/bin/python -m pip install "${{ steps.find-wheel.outputs.wheel_path }}"
.venv-test/bin/python -m pip install --no-deps ./python-pproxy-compat
.venv-test/bin/python scripts/release_artifact_smoke.py
echo "=== target evidence ==="
.venv-test/bin/python -c "import platform, sys; print('machine:', platform.machine()); print(sys.version); print('libc:', platform.libc_ver())"
echo "wheel: ${{ steps.find-wheel.outputs.wheel_path }}"
fi
echo "Smoke test passed"
musl-smoke:
# pip only accepts musllinux wheels on a musl userland, so these smokes
# run inside Alpine containers (native arch each: no QEMU needed).
name: "musllinux smoke (${{ matrix.arch }})"
needs: collect-artifacts
runs-on: ${{ matrix.os }}
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
arch: x86_64
platform: linux/amd64
- os: ubuntu-24.04-arm
arch: aarch64
platform: linux/arm64
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: release-artifacts
path: dist/
- name: Smoke musl wheel on Alpine
shell: bash
run: |
set -euo pipefail
WHEEL=$(ls dist/*musllinux*${{ matrix.arch }}*.whl | head -1)
if [[ -z "${WHEEL}" ]]; then
echo "No musllinux ${{ matrix.arch }} wheel found"
ls dist/*.whl
exit 1
fi
echo "Smoking $(basename ${WHEEL}) on Alpine (${{ matrix.platform }})"
docker run --rm --platform ${{ matrix.platform }} \
-v "${PWD}:/io" -w /io python:3.12-alpine sh -c "
set -euo pipefail
python -m pip install --upgrade pip
python -m pip install '/io/${WHEEL}'
python -m pip install --no-deps /io/python-pproxy-compat
python -c 'import platform, sys; print(\"machine:\", platform.machine()); print(sys.version); print(\"libc:\", platform.libc_ver())'
echo 'wheel: ${WHEEL}'
python /io/scripts/release_artifact_smoke.py
"
echo "musllinux ${{ matrix.arch }} smoke passed"
armv7-smoke:
name: "ARMv7 smoke (QEMU)"
needs: collect-artifacts
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: release-artifacts
path: dist/
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm
- name: Smoke GNU armv7 wheel under QEMU
shell: bash
run: |
set -euo pipefail
WHEEL=$(ls dist/*manylinux*armv7l*.whl | head -1)
if [[ -z "${WHEEL}" ]]; then
echo "No GNU armv7l wheel found"
ls dist/*.whl
exit 1
fi
echo "=== Smoking $(basename ${WHEEL}) (glibc) ==="
docker run --rm --platform linux/arm/v7 \
-v "${PWD}:/io" -w /io python:3.12-slim bash -c "
set -euo pipefail
python -m pip install --upgrade pip
python -m pip install '/io/${WHEEL}'
python -m pip install --no-deps /io/python-pproxy-compat
python -c 'import platform, sys; print(\"machine:\", platform.machine()); print(sys.version); print(\"libc:\", platform.libc_ver())'
echo 'wheel: ${WHEEL}'
python /io/scripts/release_artifact_smoke.py
"
- name: Smoke musl armv7 wheel under QEMU
shell: bash
run: |
set -euo pipefail
WHEEL=$(ls dist/*musllinux*armv7l*.whl | head -1)
if [[ -z "${WHEEL}" ]]; then
echo "No musllinux armv7l wheel found"
ls dist/*.whl
exit 1
fi
echo "=== Smoking $(basename ${WHEEL}) (musl) ==="
docker run --rm --platform linux/arm/v7 \
-v "${PWD}:/io" -w /io python:3.12-alpine sh -c "
set -euo pipefail
python -m pip install --upgrade pip
python -m pip install '/io/${WHEEL}'
python -m pip install --no-deps /io/python-pproxy-compat
python -c 'import platform, sys; print(\"machine:\", platform.machine()); print(sys.version); print(\"libc:\", platform.libc_ver())'
echo 'wheel: ${WHEEL}'
python /io/scripts/release_artifact_smoke.py
"
echo "ARMv7 smoke passed"
compat-smoke:
name: "Compatibility smoke (Python ${{ matrix.python-version }})"
needs: collect-artifacts
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: release-artifacts
path: dist/
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# Python 3.15 is pre-release at the planning baseline; allow the RC
# lane without affecting stable-version resolution.
allow-prereleases: true
- name: Find manylinux wheel
id: find-wheel
shell: bash
run: |
set -euo pipefail
WHEEL=$(ls dist/*manylinux*x86_64*.whl | head -1)
if [[ -z "${WHEEL}" ]]; then
echo "::error::No manylinux x86_64 wheel found"
exit 1
fi
echo "Found wheel: $(basename ${WHEEL})"
echo "wheel_path=${WHEEL}" >> "$GITHUB_OUTPUT"
- name: Install and smoke test
shell: bash
run: |
set -euo pipefail
python -m venv .venv-compat
.venv-compat/bin/python -m pip install --upgrade pip
.venv-compat/bin/python -m pip install "${{ steps.find-wheel.outputs.wheel_path }}"
.venv-compat/bin/python -m pip install --no-deps ./python-pproxy-compat
.venv-compat/bin/python scripts/release_artifact_smoke.py
echo "Python ${{ matrix.python-version }} compat smoke passed"
sdist-smoke:
name: "Sdist clean-install smoke"
needs: collect-artifacts
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: release-artifacts
path: dist/
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: dtolnay/rust-toolchain@stable
- name: Find sdist
id: find-sdist
shell: bash
run: |
set -euo pipefail
SDIST=$(ls dist/*.tar.gz | head -1)
if [[ -z "${SDIST}" ]]; then
echo "::error::No sdist found"
exit 1
fi
echo "Found sdist: $(basename ${SDIST})"
echo "sdist_path=${SDIST}" >> "$GITHUB_OUTPUT"
- name: Install and smoke test from sdist
shell: bash
run: |
set -euo pipefail
python -m venv .venv-sdist
.venv-sdist/bin/python -m pip install --upgrade pip
.venv-sdist/bin/python -m pip install "${{ steps.find-sdist.outputs.sdist_path }}"
.venv-sdist/bin/python -m pip install --no-deps ./python-pproxy-compat
.venv-sdist/bin/python scripts/release_artifact_smoke.py
echo "Sdist clean-install smoke passed"
publish-pypi:
name: Publish to PyPI
needs: [smoke-test, musl-smoke, armv7-smoke, compat-smoke, sdist-smoke]
if: >-
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v'))
|| (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_target == 'pypi')
runs-on: ubuntu-latest
timeout-minutes: 10
environment:
name: pypi
url: https://pypi.org/p/eggress
steps:
- uses: actions/download-artifact@v4
with:
name: release-artifacts
path: dist/
- name: List artifacts to publish
run: ls -la dist/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
# Production publication must fail on existing version, not skip
skip-existing: true