Repository navigation
435 lines (428 loc) · 22.3 KB
/
Copy pathpython-binaries.yml
File metadata and controls
435 lines (428 loc) · 22.3 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
# SPDX-License-Identifier: Apache-2.0
#
# Build (and self-verify) the eight release assets from the PYTHON package.
#
# `workflow_dispatch` ONLY, and it creates NO release and uploads NOTHING to a
# tag: this workflow exists to PROVE all eight targets CAN be produced from
# `python/`, not to publish them. Cutting a release stays release.yml's job and
# the maintainer's call -- and release.yml already ships the Python port, from
# v0.5.0, but only FOUR of these eight assets: adding the
# `aarch64-pc-windows-msvc` and Linux-arm64 runner legs was out of scope for
# that tag (a scope decision, not a platform limit -- see release.yml's
# header). Fold the missing two legs into release.yml's `build` matrix if/when
# arm64 assets are wanted; `docs/python-release-feasibility.md` carries the
# exact edits. `release.yml`'s `verify-version` job already reads
# `TAN_VERSION` via `python/scripts/version_check.py` rather than grepping
# `^version = ` out of Cargo.toml, so that half of the fold is done.
#
# Why one job per asset instead of release.yml's three runners: `cargo` cross-
# compiles, PyInstaller CANNOT. It freezes the interpreter it is RUNNING, so
# every asset must be built on its own OS+arch. Eight assets, eight native
# hosts (all eight labels are available on this PUBLIC repo -- an earlier
# revision of this comment said "private repos", which stopped being true when
# the repo went public, the same correction release.yml's own header and
# docs/release-contract.md already carry for the two unpublished arm64 assets).
#
# The two `-gnu` jobs build inside `python:3.12-slim-bullseye` (Debian 11,
# glibc 2.31) to match the floor release.yml's cargo-zigbuild pins with
# `<target>.2.31`. Building on the runner's own image instead would raise the
# floor to that image's glibc (ubuntu-24.04 = 2.39) and silently break every
# older host. MEASURED: a binary built on Debian 11 runs on glibc 2.31 and
# FAILS on 2.28 with `libpython3.12.so.1.0: version 'GLIBC_2.29' not found`.
#
# The Linux jobs shell `docker run` rather than using `container:` on purpose.
# `container: python:3.12-alpine` cannot run `actions/checkout` -- the runner
# injects a glibc-linked node into a musl image -- so the checkout happens on
# the host and only the BUILD goes into the container.
name: python-binaries
on:
workflow_dispatch:
inputs:
verify:
description: "Run the five per-asset proofs (version / --output / emit / init / CA trust anchors)"
type: boolean
default: true
permissions:
contents: read
env:
# The PACKAGE plus PyInstaller, never a hand-listed dependency set. The hand
# list is what broke: `python/tan/cli.py` imports `click.testing`, typer
# stopped depending on click, and a venv built from the list froze a binary
# that died at import with `ModuleNotFoundError: No module named 'click'`.
# `-e ./python` resolves exactly what a customer's `pip install tan-cli`
# resolves, so the build environment can no longer be quietly richer than the
# declared one. PyInstaller stays out of pyproject.toml on purpose: it is a
# build-time tool, not a runtime dependency.
#
# `[monitor]` IS installed -- decided on the numbers, not on principle.
#
# An extra is optional at runtime by definition, so the default was to leave it
# out. Measured on one host, clean venvs, after bd7079d: without it 13574636 B,
# with it 13648028 B. A 73392 B (0.54%) delta against 2.85 MB of headroom under
# the DEFAULT ceiling is not a size decision, and the thing it buys is a `tan
# monitor` that can open a serial port at all -- pyserial cannot be added to a
# `--onefile` binary after the fact, so a frozen build without the extra is a
# build whose `monitor` can never work on the machine holding it.
#
# It hides nothing: without the extra the command now refuses honestly with
# `monitor.pyserial-missing` at exit 1, naming the extra and saying a frozen
# binary resolves it at BUILD time (bd7079d guarded `_available_ports()`, the
# choke point every port-listing path routes through -- the precheck at
# `monitor_cmd.py` cannot fire under `sys.frozen`, so guarding the callers
# would have left this path open).
#
# Keep the quotes: `[monitor]` is a bash glob character class, and an unquoted
# `-e .[monitor]` is at the mercy of what happens to sit in the working
# directory.
#
# DELIBERATELY UNPINNED, not merely un-updated (tan-cli#989 review,
# finding 3): every leg below still resolves `.[monitor]` and this
# `BUILD_DEPS` live against PyPI, not from
# `release-requirements.lock.txt` -- unlike release.yml's `build` job and
# clean-host.yml's `freeze-and-smoke` job, which now install that lock
# `--require-hashes`. The two goals conflict: this workflow's whole point,
# per the paragraph above, is proving the freeze matches what `pip install
# tan-cli` resolves TODAY (the click regression this comment already
# describes is exactly the class of drift a stale lock would hide again).
# Locking it would trade that live signal for reproducing a pin that could
# already be stale. `release.yml`/`clean-host.yml` remain the only
# hash-verified, reproducible builds; this workflow (`workflow_dispatch`
# only, publishes nothing) stays an unpinned canary on purpose.
BUILD_DEPS: pyinstaller>=6.10
# Debian 11, i.e. glibc 2.31 -- NOT the runner's own image.
#
# The floor is 2.29 and it comes from the BUNDLED CPython, not the bootloader:
# `objdump -T` on the produced binary reports GLIBC_2.14 as its highest need,
# which is misleading, while the bundled libpython3.12.so.1.0 fails on Debian
# 10 with `version 'GLIBC_2.29' not found (required by libpython3.12.so.1.0)`.
# PyInstaller has no equivalent of cargo-zigbuild's `.2.31` floor flag -- THE
# BUILD IMAGE IS THE FLOOR. Building on ubuntu-24.04 would silently raise it to
# glibc 2.39 and break every older host, with nothing in this workflow failing.
# release.yml's Rust jobs pin the same 2.31 via `zigbuild_target:
# <triple>.2.31`; this pin is how the Python assets keep that promise.
GNU_IMAGE: python:3.12-slim-bullseye
MUSL_IMAGE: python:3.12-alpine
jobs:
windows:
strategy:
fail-fast: false
matrix:
include:
- asset: tan-x86_64-pc-windows-msvc.zip
os: windows-latest
machine: "0x8664" # IMAGE_FILE_MACHINE_AMD64
- asset: tan-aarch64-pc-windows-msvc.zip
# `windows-11-arm`, and it has to be: PyInstaller freezes the
# interpreter it is RUNNING and cannot cross-compile, so building
# this asset on `windows-latest` would upload an x86_64 binary under
# the aarch64 name. The `arch` step below is what refuses that.
os: windows-11-arm
machine: "0xaa64" # IMAGE_FILE_MACHINE_ARM64
runs-on: ${{ matrix.os }}
# tan-cli#855: no bound at all -- inherited GitHub's 360-minute default on
# a `workflow_dispatch`-only proof workflow nobody watches by default. 45
# is a hang catcher, not a derived budget -- measured p100 across these
# legs is ~1.6 minutes on a real run (30675989571: windows 1.2/1.5, linux
# 0.7-1.0, macos 0.7/1.6; 30555358227 the same shape), so 45 is
# comfortably ~28x that, not a number sized to the extra work this job
# does relative to clean-host.yml's `freeze-and-smoke` (20). It carries
# more setup than that sibling -- TWO checkouts per leg (this repo + a
# full alp-sdk clone) and, when `inputs.verify` is true (the default),
# `verify_binary.sh`'s five per-asset proofs on top of the arch check --
# but the measured numbers above don't back a precise multiple, so this
# comment no longer claims one.
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
repository: alplabai/alp-sdk
path: alp-sdk
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.12"
# build_binary.sh (tan-cli#349) now emits a --onedir freeze at
# dist/tan/tan.exe (+ dist/tan/_internal/) AND archives that folder to
# dist/tan.zip. The archive is the actual release-shaped asset, so it is
# what gets renamed/uploaded; the pre-archive dist/tan/tan.exe (with its
# _internal sibling still on disk right after the build) is what the
# `arch` and `verify` steps below read, since both need a RUNNABLE
# onedir tree, not a lone exe with no _internal beside it.
- name: build
shell: bash
working-directory: python
run: |
python -m venv .venv-build
.venv-build/Scripts/python -m pip install --quiet --upgrade pip
.venv-build/Scripts/python -m pip install --quiet -e ".[monitor]" $BUILD_DEPS
PYTHON=.venv-build/Scripts/python.exe bash scripts/build_binary.sh
cp dist/tan.zip "${{ matrix.asset }}"
# Same reason the macOS job runs `file`: PyInstaller freezes the host's
# arch, so a wrong runner label produces a correctly NAMED asset of the
# wrong architecture, and the extension selects by name without ever
# inspecting the file. Read the PE COFF machine field rather than shelling
# `file`, which is a Git-for-Windows accident rather than a guarantee:
# 0x8664 = AMD64, 0xaa64 = ARM64. Reads the pre-archive onedir exe
# (dist/tan/tan.exe), not the renamed .zip asset -- a .zip has no PE
# header at all.
- name: arch
shell: bash
run: |
python - "python/dist/tan/tan.exe" "${{ matrix.machine }}" <<'PY'
import struct, sys
path, want = sys.argv[1], int(sys.argv[2], 16)
with open(path, "rb") as fh:
fh.seek(0x3C)
pe = struct.unpack("<I", fh.read(4))[0]
fh.seek(pe + 4)
machine = struct.unpack("<H", fh.read(2))[0]
print(f"{path}: PE machine 0x{machine:04x} (want 0x{want:04x})")
if machine != want:
raise SystemExit(f"::error::{path} is not the architecture its asset name claims")
PY
# Runs against the pre-archive onedir tree, not the .zip -- verify_binary.sh
# executes the binary (`"$BIN" --version`), which needs its _internal
# sibling directory on disk, not zipped up.
#
# RELATIVE arguments here, `$PWD/...` in the linux and macos jobs below,
# deliberately: tan-cli#361 was a script that lost a relative path across
# its own `cd`, and it survived because all three call sites happened to
# pass absolute ones. Git Bash is also the shell the fix's cd-into-dirname
# idiom is least obvious on. Keeping one call site on each form means the
# release path itself exercises both.
- name: verify
if: inputs.verify
shell: bash
run: python/scripts/verify_binary.sh python/dist/tan/tan.exe alp-sdk
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ${{ matrix.asset }}
path: python/${{ matrix.asset }}
if-no-files-found: error
linux:
strategy:
fail-fast: false
matrix:
include:
- asset: tan-x86_64-unknown-linux-gnu.tar.gz
os: ubuntu-latest
libc: gnu
- asset: tan-aarch64-unknown-linux-gnu.tar.gz
os: ubuntu-24.04-arm
libc: gnu
- asset: tan-x86_64-unknown-linux-musl.tar.gz
os: ubuntu-latest
libc: musl
- asset: tan-aarch64-unknown-linux-musl.tar.gz
os: ubuntu-24.04-arm
libc: musl
runs-on: ${{ matrix.os }}
# Same reasoning as the `windows` job above -- see that job's comment.
# The `linux` leg additionally builds inside `docker run` (apt-bounded
# install of binutils + a venv inside the container) rather than a bare
# setup-python step, which is more setup per leg, not less; 45 still
# covers it with the same headroom the windows leg has.
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
repository: alplabai/alp-sdk
path: alp-sdk
# `binutils` is not optional: PyInstaller walks the shared-library graph
# with `objdump` and refuses without it ("ERROR: On Linux, objdump is
# required"). Nothing else is needed -- PyInstaller 6.21 publishes
# musllinux_1_1_{x86_64,aarch64} wheels, so even the musl bootloader is
# prebuilt and no compiler is involved.
#
# The build script is deliberately NOT piped. `bash scripts/build_binary.sh
# | tail -3` returns tail's status, which is how an over-ceiling artifact
# got copied out during the freeze investigation with `set -e` armed. The
# script now also quarantines an over-ceiling artifact as
# `dist/tan.oversized` so the `cp` below cannot ship one either way.
#
# build_binary.sh (tan-cli#349) emits a --onedir freeze at
# dist/tan/tan (+ dist/tan/_internal/) AND archives that folder to
# dist/tan.tar.gz. The archive is staged under the asset name for
# upload; `verify` below reads the pre-archive dist/tan/tan directly,
# since it EXECUTES the binary and needs its _internal sibling on disk.
- name: build (${{ matrix.libc }})
run: |
if [ "${{ matrix.libc }}" = musl ]; then
# Mirror first: Docker Hub rate-limits anonymous runner pulls.
img=$(bash scripts/ci/docker-pull.sh "$MUSL_IMAGE")
docker run --rm -v "$PWD/python:/w" -w /w "$img" sh -c '
set -e
apk add --no-cache binutils bash
python -m venv /tmp/v
/tmp/v/bin/pip install --quiet -e ".[monitor]" '"$BUILD_DEPS"'
PYTHON=/tmp/v/bin/python bash scripts/build_binary.sh'
else
img=$(bash scripts/ci/docker-pull.sh "$GNU_IMAGE")
docker run --rm -v "$PWD/python:/w" -v "$PWD/scripts:/scripts:ro" -w /w "$img" bash -c '
set -e
bash /scripts/ci/apt-bounded.sh update -qq
bash /scripts/ci/apt-bounded.sh install -qq -y binutils
python -m venv /tmp/v
/tmp/v/bin/pip install --quiet -e ".[monitor]" '"$BUILD_DEPS"'
PYTHON=/tmp/v/bin/python bash scripts/build_binary.sh'
fi
cp python/dist/tan.tar.gz "python/${{ matrix.asset }}"
# Verified in a runtime image with NO Python installed, which is the
# actual claim being made about a frozen binary. `debian:bullseye-slim`
# doubles as the glibc-2.31 floor check for the -gnu assets.
- name: verify
if: inputs.verify
run: |
image=debian:bullseye-slim
[ "${{ matrix.libc }}" = musl ] && image=alpine:3.20
image=$(bash scripts/ci/docker-pull.sh "$image")
docker run --rm -v "$PWD:/w" -w /w "$image" \
sh python/scripts/verify_binary.sh "/w/python/dist/tan/tan" /w/alp-sdk
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ${{ matrix.asset }}
path: python/${{ matrix.asset }}
if-no-files-found: error
macos:
strategy:
fail-fast: false
matrix:
include:
- asset: tan-x86_64-apple-darwin.tar.gz
# THE INTEL LABEL, and it has to be. `macos-latest`, `macos-14` and
# `macos-15` are all Apple silicon, and PyInstaller freezes the
# interpreter it is RUNNING -- it cannot cross-compile. Using one of
# those here BUILDS FINE and uploads an arm64 binary under the
# x86_64 asset name; the extension selects that asset by name and
# never inspects the file, so the failure lands on an Intel Mac at
# runtime (`Bad CPU type in executable`), not in CI. `file` is run on
# the artifact below for exactly this reason.
os: macos-15-intel
# CPU_TYPE_X86_64, the Mach-O header field the `arch` step below
# compares against. Carried in the matrix for the same reason
# `machine` is on the Windows leg: the expected value belongs
# beside the asset NAME it is a claim about, so adding a row
# cannot forget to state one.
cputype: "0x01000007"
- asset: tan-aarch64-apple-darwin.tar.gz
os: macos-latest
cputype: "0x0100000c" # CPU_TYPE_ARM64
runs-on: ${{ matrix.os }}
# Same reasoning as the `windows` job above -- see that job's comment.
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
repository: alplabai/alp-sdk
path: alp-sdk
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.12"
# build_binary.sh (tan-cli#349) emits a --onedir freeze at dist/tan/tan
# (+ dist/tan/_internal/) AND archives that folder to dist/tan.tar.gz.
# The archive is what gets renamed/uploaded; `arch` and `verify` below
# read the pre-archive dist/tan/tan directly, since both need the
# _internal sibling still on disk (an arch check on a lone binary would
# still work, but verify EXECUTES it, so keep them consistent).
- name: build
working-directory: python
run: |
python3 -m venv .venv-build
.venv-build/bin/python -m pip install --quiet --upgrade pip
.venv-build/bin/python -m pip install --quiet -e ".[monitor]" $BUILD_DEPS
PYTHON=.venv-build/bin/python bash scripts/build_binary.sh
cp dist/tan.tar.gz "${{ matrix.asset }}"
# The arch must be PROVED, because a PyInstaller build cannot: it always
# produces the host's arch, so a wrong runner label yields a correctly
# NAMED binary of the wrong architecture.
#
# WHAT THAT COSTS *HERE*, stated accurately (tan-cli#500 review). This
# workflow is `workflow_dispatch` ONLY and every leg ends in
# `actions/upload-artifact` -- no release is created and no asset reaches
# a tag, so no customer can receive a binary from this file. What a
# vacuous check costs here is FALSE ASSURANCE in a proof-only workflow:
# this job exists to prove all eight targets can be produced, and a step
# that cannot fail proves nothing about two of them.
#
# The customer-facing half -- `Bad CPU type in executable` on an Intel
# Mac -- belongs to `release.yml`'s `build` job, which a `v*` push runs
# and which had NO arch check at all until tan-cli#500 added the same one
# there for the same two darwin rows.
#
# This step was `run: file "python/dist/tan/tan"` -- no comparison, no
# non-zero path, so it could not fail on the very thing the comment above
# says it exists to refuse (tan-cli#500). The Windows leg had it right all
# along: read the header field and refuse on mismatch against the matrix.
# Reads the Mach-O header rather than parsing `file`'s prose, for the same
# reason the Windows leg reads the PE COFF machine word -- `file`'s output
# is a human string that has changed spelling before.
- name: arch
run: |
python3 - "python/dist/tan/tan" "${{ matrix.cputype }}" <<'PY'
import struct, sys
path, want = sys.argv[1], int(sys.argv[2], 16)
with open(path, "rb") as fh:
head = fh.read(8)
if len(head) < 8:
raise SystemExit(f"::error::{path} is too short to hold a Mach-O header")
magic, cputype = struct.unpack("<II", head)
# Fat magic is stored BIG-endian, so it reads back byte-swapped here.
# Refused explicitly rather than mis-parsed: a universal binary would
# satisfy both asset names at once, which is the opposite of what
# per-architecture assets are for.
if magic in (0xBEBAFECA, 0xCAFEBABE, 0xBFBAFECA, 0xCAFEBABF):
raise SystemExit(
f"::error::{path} is a UNIVERSAL (fat) binary; these assets are "
f"per-architecture and a fat one would ship under both names")
if magic not in (0xFEEDFACF, 0xFEEDFACE):
raise SystemExit(f"::error::{path} is not a Mach-O binary (magic 0x{magic:08x})")
print(f"{path}: Mach-O cputype 0x{cputype:08x} (want 0x{want:08x})")
if cputype != want:
raise SystemExit(f"::error::{path} is not the architecture its asset name claims")
PY
- name: verify
if: inputs.verify
run: bash python/scripts/verify_binary.sh "$PWD/python/dist/tan/tan" "$PWD/alp-sdk"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ${{ matrix.asset }}
path: python/${{ matrix.asset }}
if-no-files-found: error
# Same shape as release.yml's own step (`sha256sum * > checksums.txt` inside
# the assets dir), so the published file's format is identical. Uploaded as an
# artifact only -- nothing here touches a release.
checksums:
needs: [windows, linux, macos]
runs-on: ubuntu-latest
# tan-cli#855: download 8 small artifacts + `sha256sum` them -- no build,
# no toolchain, no network beyond the artifact download. Matches
# e2e-container.yml's `shellcheck` (5), the lightest bound in the repo for
# a job that still does real, if brief, work.
timeout-minutes: 5
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
path: assets
merge-multiple: true
- name: checksums.txt
working-directory: assets
run: |
ls -l
test "$(ls | wc -l)" -eq 8 || { echo "::error::expected 8 assets"; exit 1; }
sha256sum * > checksums.txt
cat checksums.txt
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: checksums.txt
path: assets/checksums.txt