Repository navigation
361 lines (351 loc) · 15.4 KB
/
Copy pathrelease.yml
File metadata and controls
361 lines (351 loc) · 15.4 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
name: release
on:
push:
tags: ["v*"]
workflow_dispatch:
permissions:
contents: read
# Never allow two runs to mutate the same release concurrently.
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
validate:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Require a version tag matching app and executable metadata
env:
RELEASE_TAG: ${{ github.ref_name }}
RELEASE_REF_TYPE: ${{ github.ref_type }}
run: |
python - <<'PY'
import ast
import os
import re
from pathlib import Path
tag = os.environ["RELEASE_TAG"]
if os.environ["RELEASE_REF_TYPE"] != "tag":
raise SystemExit("Release dispatch must select a tag, not a branch")
if not re.fullmatch(r"v\d+\.\d+\.\d+", tag):
raise SystemExit("Expected a vMAJOR.MINOR.PATCH release tag")
notes = Path("docs/releases") / f"{tag[1:]}.md"
if not notes.is_file():
raise SystemExit(f"Release notes file is required: {notes}")
module = ast.parse(Path("zcode_gateway/__init__.py").read_text(encoding="utf-8"))
versions = [ast.literal_eval(node.value) for node in module.body
if isinstance(node, ast.Assign)
and any(isinstance(t, ast.Name) and t.id == "__version__" for t in node.targets)]
if versions != [tag[1:]]:
raise SystemExit(f"Tag {tag} does not match app version {versions}")
expected = tuple(map(int, tag[1:].split("."))) + (0,)
metadata = ast.parse(Path("scripts/packaging/exe_version.txt").read_text(encoding="utf-8"))
fixed = {node.arg: ast.literal_eval(node.value) for node in ast.walk(metadata)
if isinstance(node, ast.keyword) and node.arg in ("filevers", "prodvers")}
strings = {ast.literal_eval(node.args[0]): ast.literal_eval(node.args[1])
for node in ast.walk(metadata) if isinstance(node, ast.Call)
and isinstance(node.func, ast.Name) and node.func.id == "StringStruct"
and len(node.args) == 2}
if fixed != {"filevers": expected, "prodvers": expected}:
raise SystemExit(f"Executable numeric versions must be {expected}: {fixed}")
for key in ("FileVersion", "ProductVersion"):
if strings.get(key) != ".".join(map(str, expected)):
raise SystemExit(f"Executable {key} does not match {tag}")
PY
test:
needs: validate
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
python-version: "3.13"
python: .venv/Scripts/python
requirements: requirements/windows.txt
- os: ubuntu-22.04
python-version: "3.12"
python: .venv/bin/python
requirements: requirements/server.txt
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
env:
PYTHON: ${{ matrix.python }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: actions/setup-node@v4
with:
node-version: "22"
- name: Create venv and install runtime and UI test dependencies
run: |
python -m venv .venv
"$PYTHON" -m pip install --upgrade pip
"$PYTHON" -m pip install -r "${{ matrix.requirements }}" -r requirements/dev.txt playwright Pillow PySocks cryptography
- name: Install Chromium (Windows)
if: runner.os == 'Windows'
run: '"$PYTHON" -m playwright install chromium'
- name: Install Chromium and system libraries (Linux)
if: runner.os == 'Linux'
run: '"$PYTHON" -m playwright install --with-deps chromium'
- name: Require a working browser before running UI tests
run: |
"$PYTHON" - <<'PY'
from playwright.sync_api import sync_playwright
with sync_playwright() as runtime:
browser = runtime.chromium.launch()
page = browser.new_page()
page.set_content("<title>release-browser-check</title>")
assert page.title() == "release-browser-check"
browser.close()
PY
- name: Run tests
run: '"$PYTHON" -m pytest tests -q --junitxml=release-tests.xml'
- name: Reject skipped browser tests
run: |
"$PYTHON" - <<'PY'
import xml.etree.ElementTree as ET
ui_modules = {"test_auto_generate_ui", "test_model_quota_ui", "test_signup_form_transition", "test_update_ui"}
failures = []
for case in ET.parse("release-tests.xml").iter("testcase"):
skipped = case.find("skipped")
if skipped is None:
continue
reason = " ".join(skipped.itertext()) + " " + skipped.get("message", "")
if (set(case.get("classname", "").split(".")) & ui_modules
or any(word in reason.lower() for word in ("playwright", "chromium", "browser"))):
failures.append(f"{case.get('classname')}.{case.get('name')}: {reason}")
if failures:
raise SystemExit("Browser tests must not skip in releases:\n" + "\n".join(failures))
PY
build-windows:
needs: test
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- uses: oven-sh/setup-bun@v2
with:
bun-version: "1.3.14"
- name: Test native helper sources before packaging
working-directory: tools/captcha-mint
run: |
bun install --frozen-lockfile
bun run test
- name: Create venv and install build dependencies
run: |
python -m venv .venv
.\.venv\Scripts\python -m pip install --upgrade pip
.\.venv\Scripts\python -m pip install -r requirements/windows.txt pyinstaller
- name: Build executable with embedded native sidecar
run: .\scripts\build\windows.ps1
- name: Verify sidecar and executable version
shell: pwsh
env:
RELEASE_TAG: ${{ github.ref_name }}
run: |
if (-not (Test-Path .\tools\captcha-mint\captcha-mint.exe -PathType Leaf)) {
throw "captcha-mint.exe was not built"
}
$expected = $env:RELEASE_TAG.Substring(1) + ".0"
$version = (Get-Item .\.local\dist\ZcodeGateway.exe).VersionInfo
if ($version.FileVersion -ne $expected -or $version.ProductVersion -ne $expected) {
throw "Built executable version does not match $expected"
}
- name: Smoke test the packaged Windows application with dummy state
shell: pwsh
run: |
$env:AUDIT_BINARY = (Resolve-Path (Join-Path $env:GITHUB_WORKSPACE ".local/dist/ZcodeGateway.exe")).Path
$python = (Resolve-Path .\.venv\Scripts\python.exe).Path
$smoke = (Resolve-Path .\scripts\smoke\frozen_local.py).Path
$scratch = Join-Path $env:RUNNER_TEMP "frozen-windows-smoke"
New-Item -ItemType Directory -Path $scratch -Force | Out-Null
Push-Location $scratch
try { & $python $smoke; if ($LASTEXITCODE -ne 0) { throw "Frozen smoke test failed" } }
finally { Pop-Location }
- name: Checksum Windows release assets
run: |
$h = (Get-FileHash .\.local\dist\ZcodeGateway.exe -Algorithm SHA256).Hash.ToLower()
"$h ZcodeGateway.exe" | Out-File -Encoding ascii .\.local\dist\checksums.sha256
- uses: actions/upload-artifact@v4
with:
name: release-windows
if-no-files-found: error
include-hidden-files: true
path: |
.local/dist/ZcodeGateway.exe
.local/dist/checksums.sha256
build-linux:
needs: test
# PyInstaller inherits this glibc baseline; do not move to ubuntu-latest.
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: oven-sh/setup-bun@v2
with:
bun-version: "1.3.14"
- name: Test native helper sources before packaging
working-directory: tools/captcha-mint
run: |
bun install --frozen-lockfile
bun run test
- name: Create venv and install headless build dependencies
run: |
python -m venv .venv
.venv/bin/python -m pip install --upgrade pip
.venv/bin/python -m pip install -r requirements/server.txt PySocks pyinstaller
- name: Build Linux binary with embedded native sidecar
run: bash scripts/build/linux.sh
- name: Verify the native sidecar and runtime library baseline
run: |
set -euo pipefail
test -x tools/captcha-mint/captcha-mint
test -x .local/dist/ZcodeGateway
ldd --version
# ldd can succeed while listing unresolved libraries; check both ELFs.
for binary in .local/dist/ZcodeGateway tools/captcha-mint/captcha-mint; do
ldd "$binary" | tee "$RUNNER_TEMP/ldd.txt"
if grep -q 'not found' "$RUNNER_TEMP/ldd.txt"; then
echo "Unresolved runtime libraries in $binary" >&2
exit 1
fi
done
- name: Smoke test the packaged Linux application with dummy state
run: |
export AUDIT_BINARY="$GITHUB_WORKSPACE/.local/dist/ZcodeGateway"
scratch=$(mktemp -d "$RUNNER_TEMP/frozen-linux-smoke.XXXXXX")
cd "$scratch"
"$GITHUB_WORKSPACE/.venv/bin/python" "$GITHUB_WORKSPACE/scripts/smoke/frozen_local.py"
- name: Checksum Linux release assets (sidecar is embedded, not uploaded)
run: |
cp install-linux.sh .local/dist/install-linux.sh
(cd .local/dist && sha256sum ZcodeGateway install-linux.sh > checksums-linux.sha256)
- uses: actions/upload-artifact@v4
with:
name: release-linux
if-no-files-found: error
include-hidden-files: true
path: |
.local/dist/ZcodeGateway
.local/dist/checksums-linux.sha256
.local/dist/install-linux.sh
publish:
needs: [build-windows, build-linux]
runs-on: ubuntu-22.04
permissions:
contents: write
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RELEASE_TAG: ${{ github.ref_name }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: actions/download-artifact@v4
with:
name: release-windows
path: release-assets
- uses: actions/download-artifact@v4
with:
name: release-linux
path: release-assets
- name: Verify the complete artifact set and every payload checksum
run: |
python - <<'PY'
import hashlib
import re
from pathlib import Path
root = Path("release-assets")
manifests = {"checksums.sha256": {"ZcodeGateway.exe"},
"checksums-linux.sha256": {"ZcodeGateway", "install-linux.sh"}}
expected = set(manifests) | set().union(*manifests.values())
if {p.name for p in root.iterdir()} != expected:
raise SystemExit("Release must contain exactly the five expected asset leafs")
if any(not p.is_file() or p.is_symlink() or p.stat().st_size == 0 for p in root.iterdir()):
raise SystemExit("Release assets must be nonempty regular files")
for manifest, payloads in manifests.items():
seen = set()
for line in (root / manifest).read_text(encoding="ascii").splitlines():
match = re.fullmatch(r"([0-9a-f]{64}) ([A-Za-z0-9_.-]+)", line)
if match is None:
raise SystemExit(f"Invalid checksum entry in {manifest}: {line!r}")
digest, name = match.groups()
if name not in payloads or name in seen:
raise SystemExit(f"Unexpected or duplicate checksum leaf: {name}")
seen.add(name)
if hashlib.sha256((root / name).read_bytes()).hexdigest() != digest:
raise SystemExit(f"Checksum mismatch for {name}")
if seen != payloads:
raise SystemExit(f"Incomplete checksum manifest: {manifest}")
PY
- name: Create or resume a draft without modifying a public release
run: |
set -euo pipefail
notes_file="docs/releases/${RELEASE_TAG#v}.md"
test -f "$notes_file"
# A failed lookup is not treated as absence: auth/network failures fail closed.
gh api --paginate "repos/$GH_REPO/releases?per_page=100" --jq '.[] | {tag_name, draft}' | jq -s '.' > releases.json
state=$(jq -r --arg tag "$RELEASE_TAG" '[.[] | select(.tag_name == $tag)] | if length == 0 then "absent" elif length == 1 and .[0].draft then "draft" else "public" end' releases.json)
case "$state" in
absent)
gh release create "$RELEASE_TAG" --verify-tag --draft --notes-file "$notes_file" --title "$RELEASE_TAG"
;;
draft) ;;
*) echo "Refusing to overwrite existing public release $RELEASE_TAG" >&2; exit 1 ;;
esac
gh release edit "$RELEASE_TAG" --notes-file "$notes_file"
- name: Upload all five assets while the release remains a draft
run: |
gh release upload "$RELEASE_TAG" \
release-assets/ZcodeGateway.exe \
release-assets/checksums.sha256 \
release-assets/ZcodeGateway \
release-assets/checksums-linux.sha256 \
release-assets/install-linux.sh --clobber
- name: Verify uploaded assets before publishing
run: |
set -euo pipefail
gh release view "$RELEASE_TAG" --json isDraft,assets > uploaded-release.json
python - <<'PY'
import json
from pathlib import Path
release = json.loads(Path("uploaded-release.json").read_text())
expected = {p.name for p in Path("release-assets").iterdir()}
names = [asset["name"] for asset in release["assets"]]
if not release["isDraft"] or len(names) != len(expected) or set(names) != expected:
raise SystemExit("Release must still be a draft with exactly the five expected assets")
PY
gh release download "$RELEASE_TAG" --dir uploaded-assets
python - <<'PY'
import hashlib
from pathlib import Path
for local in Path("release-assets").iterdir():
uploaded = Path("uploaded-assets") / local.name
if hashlib.sha256(local.read_bytes()).digest() != hashlib.sha256(uploaded.read_bytes()).digest():
raise SystemExit(f"Uploaded asset does not match verified artifact: {local.name}")
PY
- name: Publish only the fully verified draft
run: gh release edit "$RELEASE_TAG" --draft=false