#!/usr/bin/env python3 """ End-to-end release builder and checksum verifier for UnsolvedMed v1.0.0. Runs: 1. scripts/validate.py 2. scripts/deduplicate.py 3. scripts/audit_samples.py 4. scripts/generate_dataset_card.py 5. Computes SHA-256 checksums for all release artifacts and updates releases/release_manifest.json """ import hashlib import json import subprocess import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent def sha256_file(path: Path) -> str: h = hashlib.sha256() with path.open("rb") as f: for chunk in iter(lambda: f.read(1024 * 1024), b""): h.update(chunk) return h.hexdigest() def main() -> int: for script in ["validate.py", "deduplicate.py", "audit_samples.py", "generate_dataset_card.py"]: print(f"=== Running {script} ===") res = subprocess.run([sys.executable, str(ROOT / "scripts" / script)], cwd=str(ROOT)) if res.returncode != 0: print(f"Release build failed at {script}") return res.returncode manifest_path = ROOT / "releases" / "release_manifest.json" manifest = json.loads(manifest_path.read_text(encoding="utf-8")) checksums = {} for rel_path in manifest["files"] + ["README.md", "DATASET_CARD.md"]: fpath = ROOT / rel_path checksums[rel_path] = { "sha256": sha256_file(fpath), "bytes": fpath.stat().st_size, } manifest["checksums"] = checksums manifest_path.write_text(json.dumps(manifest, indent=2, ensure_ascii=False) + "\n", encoding="utf-8") print("=== Updated releases/release_manifest.json with SHA-256 checksums ===") return 0 if __name__ == "__main__": sys.exit(main())