Repository navigation
Expand file tree
/
Copy pathrelease_doctor.py
More file actions
380 lines (343 loc) · 16.6 KB
/
Copy pathrelease_doctor.py
File metadata and controls
380 lines (343 loc) · 16.6 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
#!/usr/bin/env python3
"""Read-only release-day control-plane diagnostics."""
from __future__ import annotations
import json
import os
import shutil
import subprocess
from pathlib import Path
if __package__:
from . import collect_release_bundle as collector
from . import release_publication as publication
from . import release_readiness as readiness
else:
import sys
sys.path.insert(0, str(Path(__file__).resolve().parent))
import collect_release_bundle as collector
import release_publication as publication
import release_readiness as readiness
EXPECTED_PLATFORMS = (
"linux-x64",
"linux-arm64",
"darwin-x64",
"darwin-arm64",
"win32-x64",
"win32-arm64",
)
EXPECTED_DESKTOP_PLATFORMS = ("darwin-arm64", "win32-x64", "win32-arm64")
EXPECTED_SUPPLEMENTAL_DESKTOP_PLATFORMS = ("darwin-x64",)
REQUIRED_TOOLS = ("git", "gh", "npm", "node", "python3", "bash")
class DoctorError(RuntimeError):
pass
def _record(checks: list[dict], name: str, fn) -> None:
try:
detail = fn()
except Exception as exc: # bounded diagnostic aggregator; individual checks stay explicit
checks.append({"name": name, "status": "failed", "detail": str(exc)})
else:
checks.append({"name": name, "status": "passed", "detail": detail})
def _require_tools() -> str:
missing = [name for name in REQUIRED_TOOLS if shutil.which(name) is None]
if missing:
raise DoctorError(f"missing required release tools: {', '.join(missing)}")
return ", ".join(REQUIRED_TOOLS)
def _platform_contract(root: Path) -> str:
if tuple(collector.PLATFORMS) != EXPECTED_PLATFORMS:
raise DoctorError(
f"collector platform contract drift: expected={EXPECTED_PLATFORMS} actual={tuple(collector.PLATFORMS)}"
)
if tuple(collector.DESKTOP_PLATFORMS) != EXPECTED_DESKTOP_PLATFORMS:
raise DoctorError(
f"primary Desktop release platform contract drift: actual={tuple(collector.DESKTOP_PLATFORMS)}"
)
if tuple(collector.SUPPLEMENTAL_DESKTOP_PLATFORMS) != EXPECTED_SUPPLEMENTAL_DESKTOP_PLATFORMS:
raise DoctorError(
"supplemental Desktop release platform contract drift: "
f"actual={tuple(collector.SUPPLEMENTAL_DESKTOP_PLATFORMS)}"
)
manifest_path = root / "npm/webcodex/manifest.example.json"
try:
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
except (OSError, UnicodeDecodeError, json.JSONDecodeError) as exc:
raise DoctorError("npm manifest.example.json is unreadable") from exc
artifacts = manifest.get("artifacts")
if not isinstance(artifacts, dict) or tuple(artifacts) != EXPECTED_PLATFORMS:
raise DoctorError(
f"npm manifest platform contract drift: expected={EXPECTED_PLATFORMS} actual={tuple(artifacts) if isinstance(artifacts, dict) else None}"
)
return (
"six-platform npm runtime contract plus primary Desktop "
f"{', '.join(EXPECTED_DESKTOP_PLATFORMS)} and supplemental Desktop "
f"{', '.join(EXPECTED_SUPPLEMENTAL_DESKTOP_PLATFORMS)}: {', '.join(EXPECTED_PLATFORMS)}"
)
def _version_contract(root: Path, version: str) -> str:
versions = publication._package_versions(root)
mismatches = {name: value for name, value in versions.items() if value != version}
if mismatches:
detail = " ".join(f"{name}={value}" for name, value in versions.items())
raise DoctorError(f"canonical release version mismatch: requested={version} {detail}")
return "Cargo, npm, Desktop package, Desktop Cargo, and Tauri app versions match"
def _workflow_contract(root: Path) -> str:
ci = (root / ".github/workflows/ci.yml").read_text(encoding="utf-8")
extended = (root / ".github/workflows/extended-native.yml").read_text(encoding="utf-8")
readiness_workflow = (root / ".github/workflows/release-readiness.yml").read_text(encoding="utf-8")
build = (root / ".github/workflows/release-build.yml").read_text(encoding="utf-8")
intel_desktop = (root / ".github/workflows/release-desktop-darwin-x64.yml").read_text(encoding="utf-8")
release_image = (root / ".github/workflows/release-image.yml").read_text(encoding="utf-8")
download_page = (root / ".github/workflows/download-page.yml").read_text(encoding="utf-8")
required = {
"ci.yml": (
("apps/desktop/package-lock.json", ci),
("test-windows-desktop:", ci),
("DESKTOP_RESULT", ci),
("prepare_desktop_bundle.ps1", ci),
("desktop_install_windows_smoke.ps1", ci),
("prepare_desktop_bundle_macos.py", ci),
("desktop_install_macos_smoke.sh", ci),
("darwin-arm64", ci),
("test-docker-server:", ci),
("needs_docker", ci),
("linux/amd64", ci),
("'release/**'", ci),
),
"extended-native.yml": (
("workflow_call:", extended),
("workflow_dispatch:", extended),
("ubuntu-24.04-arm", extended),
("macos-15-intel", extended),
("windows-11-arm", extended),
("darwin-x64", extended),
("win32-arm64", extended),
("prepare_desktop_bundle.ps1", extended),
("desktop_install_windows_smoke.ps1", extended),
("prepare_desktop_bundle_macos.py", extended),
("desktop_install_macos_smoke.sh", extended),
),
"release-readiness.yml": (
("ci_run_id", readiness_workflow),
("evidence_run_id", readiness_workflow),
("- 'release/v*'", readiness_workflow),
("source_ref:", readiness_workflow),
('refs/heads/$INPUT_SOURCE_REF', readiness_workflow),
("uses: ./.github/workflows/extended-native.yml", readiness_workflow),
("if: github.event_name == 'push' || inputs.source_ref == 'main'", readiness_workflow),
("linux/amd64", readiness_workflow),
("linux/arm64", readiness_workflow),
),
"release-build.yml": tuple((platform, build) for platform in EXPECTED_PLATFORMS)
+ (
("macos-15-intel", build),
("windows-11-arm", build),
("ubuntu-24.04-arm", build),
("prepare_desktop_bundle.ps1", build),
("desktop_install_windows_smoke.ps1", build),
("prepare_desktop_bundle_macos.py", build),
("desktop_install_macos_smoke.sh", build),
("desktop_artifacts", build),
('refs/tags/$tag', build),
("webcodex-desktop-v$env:VERSION-$env:WEBCODEX_RELEASE_PLATFORM-setup.exe", build),
("webcodex-desktop-v$VERSION-$WEBCODEX_RELEASE_PLATFORM.dmg", build),
('desktop_dist="$GITHUB_WORKSPACE/dist"', build),
('$installerPath = Join-Path $desktopDist $installerName', build),
("DESKTOP_INSTALLER_PATH=$installerPath", build),
('--dmg "${{ steps.desktop_dmg.outputs.path }}"', build),
("-Installer $env:DESKTOP_INSTALLER_PATH", build),
("dist/webcodex-desktop-*.dmg", build),
("dist/webcodex-desktop-*-${{ matrix.platform }}-setup.exe", build),
('bash scripts/macos_sign_runner.sh target/release/webcodex-runner "$APPLE_SIGNING_IDENTITY" "$WEBCODEX_MACOS_SIGNING_MODE"', build),
("macos_finalize_desktop.sh", build),
("macos_ci_signing_setup.sh", build),
("macos_finalize_dmg.sh", build),
("public release requires persistent signing identity", build),
('expected_notarized = expected_signing == "developer-id"', build),
(" preflight:", build),
("Fail fast on deterministic release contracts", build),
("bash scripts/release_check.sh --static-only", build),
("include_unified_installers:", build),
("if: inputs.include_unified_installers", build),
("!inputs.include_unified_installers || needs.unified-native.result == 'success'", build),
("export CARGO_TARGET_DIR=/work/target", build),
('export CARGO_TARGET_DIR="$GITHUB_WORKSPACE/target"', build),
('desktop="$CARGO_TARGET_DIR/release/webcodex-desktop"', build),
),
"release-desktop-darwin-x64.yml": (
("types: [published]", intel_desktop),
("workflow_dispatch:", intel_desktop),
("macos-15-intel", intel_desktop),
("contents: write", intel_desktop),
("webcodex-v$VERSION-$PLATFORM.tar.gz", intel_desktop),
("SHA256SUMS", intel_desktop),
("gh release upload", intel_desktop),
("desktop_install_macos_smoke.sh", intel_desktop),
("desktop_install_macos_smoke.sh", intel_desktop),
("macos_ci_signing_setup.sh", intel_desktop),
("macos_finalize_dmg.sh", intel_desktop),
("Treat an already-published DMG as immutable authority", intel_desktop),
("--build-info-json", intel_desktop),
("source_sha.startswith(commit)", intel_desktop),
("immutable runtime binaries disagree on commit identity", intel_desktop),
),
"release-image.yml": (
("WEBCODEX_GIT_COMMIT=${{ needs.resolve.outputs.source_short }}", release_image),
("--build-info-json", release_image),
("source_sha.startswith(commit)", release_image),
),
"download-page.yml": (
("Resolve optional installer manifest", download_page),
('echo "has_installers=false" >> "$GITHUB_OUTPUT"', download_page),
("if: steps.manifest.outputs.has_installers == 'true'", download_page),
),
}
missing = []
for filename, tokens in required.items():
for token, body in tokens:
if token not in body:
missing.append(f"{filename}:{token}")
if missing:
raise DoctorError(f"release workflow contract is missing: {', '.join(missing)}")
forbidden_daily = ("macos-15-intel", "windows-11-arm", "ubuntu-24.04-arm", "test-windows-arm64:", "test-linux-arm64:")
leaked = [token for token in forbidden_daily if token in ci]
if leaked:
raise DoctorError(f"ordinary CI regained extended-native lanes: {', '.join(leaked)}")
if "packages: write" in readiness_workflow or "actions/upload-artifact" in readiness_workflow:
raise DoctorError("release-readiness gained publication/upload authority")
if "prepare_desktop_bundle.ps1" in readiness_workflow or "tauri" in readiness_workflow.lower():
raise DoctorError("release-readiness gained Desktop candidate build responsibility")
apple_secret_surfaces = {
"ci.yml": ci,
"extended-native.yml": extended,
"release-readiness.yml": readiness_workflow,
}
leaked_apple_secrets = [name for name, body in apple_secret_surfaces.items() if "secrets.APPLE_" in body]
if leaked_apple_secrets:
raise DoctorError(
"disposable CI unexpectedly depends on Apple release-signing credentials: "
+ ", ".join(leaked_apple_secrets)
)
return "main/release-branch CI, precomputed release-source evidence, persistent macOS release signing, and tag-bound authoritative build contracts are consistent"
def _compile_verifiers(root: Path) -> str:
for relative in (
"scripts/collect_release_bundle.py",
"scripts/prepare_release_metadata.py",
"scripts/verify_public_release.py",
"scripts/prepare_server_deployment_assets.py",
"scripts/release_publication.py",
"scripts/release_readiness.py",
):
source = (root / relative).read_text(encoding="utf-8")
compile(source, relative, "exec")
return "collector, release metadata, public verifier, deployment metadata, publication, and readiness Python parse cleanly"
def _actionlint(root: Path) -> str:
executable = shutil.which("actionlint")
if executable is None:
fallback = Path.home() / "go/bin/actionlint"
executable = str(fallback) if fallback.is_file() and os.access(fallback, os.X_OK) else None
if executable is None:
return "optional: actionlint not installed"
result = subprocess.run(
[
executable,
str(root / ".github/workflows/ci.yml"),
str(root / ".github/workflows/extended-native.yml"),
str(root / ".github/workflows/release-readiness.yml"),
str(root / ".github/workflows/release-build.yml"),
str(root / ".github/workflows/release-image.yml"),
str(root / ".github/workflows/release-desktop-darwin-x64.yml"),
],
cwd=root,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
timeout=60,
check=False,
)
if result.returncode != 0:
detail = (result.stderr or result.stdout).strip()
raise DoctorError(f"actionlint failed: {detail[:2000]}")
return "actionlint passed"
def run_doctor(
*,
repo: str,
version: str,
source_sha: str,
source_ref: str = "main",
root: Path,
timeout: float,
) -> dict:
source_root = root.absolute()
source = collector.normalize_source_sha(source_sha)
release_version = publication.normalize_version(version)
release_source_ref = publication.normalize_release_source_ref(source_ref, release_version)
checks: list[dict] = []
_record(checks, "required-tools", _require_tools)
_record(checks, "six-platform-contract", lambda: _platform_contract(source_root))
_record(checks, "version-contract", lambda: _version_contract(source_root, release_version))
_record(checks, "workflow-contract", lambda: _workflow_contract(source_root))
_record(checks, "python-verifiers", lambda: _compile_verifiers(source_root))
_record(checks, "actionlint", lambda: _actionlint(source_root))
preflight_result: dict | None = None
def preflight_check() -> str:
nonlocal preflight_result
preflight_result = publication.preflight_release(
repo=repo,
version=release_version,
source_sha=source,
source_ref=release_source_ref,
root=source_root,
timeout=timeout,
)
return "release source/version/namespaces and GitHub/npm publication identities passed"
_record(checks, "publication-preflight", preflight_check)
ci_result: dict | None = None
def ci_check() -> str:
nonlocal ci_result
client = collector.GitHubClient(repo, collector.resolve_github_token(), timeout)
ci_result = readiness._successful_source_ci_run(client, source, release_source_ref)
return (
f"exact-source CI run {ci_result['id']} attempt {ci_result['run_attempt']} "
f"is successful for {release_source_ref}"
)
_record(checks, "exact-source-ci", ci_check)
evidence_result: dict | None = None
def evidence_check() -> str:
nonlocal evidence_result
if not release_source_ref.startswith("release/"):
return "main-source release uses readiness-dispatch evidence fallback"
client = collector.GitHubClient(repo, collector.resolve_github_token(), timeout)
evidence_result = readiness._successful_source_evidence_run(client, source, release_source_ref)
return (
f"exact-source release evidence run {evidence_result['id']} attempt "
f"{evidence_result['run_attempt']} is successful for {release_source_ref}"
)
_record(checks, "exact-source-release-evidence", evidence_check)
def release_list_check() -> str:
client = collector.GitHubClient(repo, collector.resolve_github_token(), timeout)
payload = publication._github_json_array(client, "/releases?per_page=1&page=1")
return "authenticated bounded GitHub Release listing is readable (draft-capable lookup path)"
_record(checks, "github-release-listing", release_list_check)
failures = [check for check in checks if check["status"] != "passed"]
return {
"status": "passed" if not failures else "failed",
"repo": repo,
"version": release_version,
"source_ref": release_source_ref,
"source_sha": source,
"checks": checks,
"failed_checks": [check["name"] for check in failures],
"preflight": preflight_result,
"source_ci": (
{"run_id": ci_result["id"], "run_attempt": ci_result["run_attempt"], "url": ci_result["html_url"]}
if ci_result is not None
else None
),
"source_evidence": (
{
"run_id": evidence_result["id"],
"run_attempt": evidence_result["run_attempt"],
"url": evidence_result["html_url"],
}
if evidence_result is not None
else None
),
"mutations_performed": False,
}