#!/usr/bin/env python3 """Metadata consistency gate for the beta release. Checks that the tool version, Cargo files, tool manifest, public spec, changelog, release notes and CI configuration describe the same facts. This is a documentation/contract gate, not a functional test. """ from __future__ import annotations import json import re import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] def fail(message: str) -> "NoReturn": print(f"release-metadata: FAIL: {message}", file=sys.stderr) raise SystemExit(1) def main() -> int: cargo = (ROOT / "Cargo.toml").read_text(encoding="utf-8") match = re.search(r'(?m)^version\s*=\s*"([^"]+)"', cargo) if not match: fail("Cargo.toml has no version") version = match.group(1) if not re.fullmatch(r"\d+\.\d+\.\d+-beta\.\d+", version): fail(f"version {version} is not a beta semver (expected x.y.z-beta.N)") lock = (ROOT / "Cargo.lock").read_text(encoding="utf-8") if not re.search( r'\[\[package\]\]\nname = "marqdo-knowledge"\nversion = "' + re.escape(version) + r'"', lock, ): fail("Cargo.lock version does not match Cargo.toml") tool = json.loads((ROOT / "packaging/tool.json").read_text(encoding="utf-8")) expected = { "schema": "marqdo.cli-tool", "schema_version": 1, "name": "marqdo-knowledge", "version": version, "command": "knowledge", "entrypoint": "bin/marqdo-knowledge", "requires": {"api_revision": 1, "analysis": 3}, } if tool != expected: fail(f"packaging/tool.json is not the current exact manifest: {tool}") spec = (ROOT / "spec/knowledge.md").read_text(encoding="utf-8") if f'"version": "{version}"' not in spec: fail("spec/knowledge.md tool identity version is stale") if '"requires": {"api_revision": 1, "analysis": 3}' not in spec: fail("spec/knowledge.md requirements are stale") changelog = (ROOT / "CHANGELOG.md").read_text(encoding="utf-8") if f"## {version}" not in changelog: fail("CHANGELOG.md has no section for this version") notes = ROOT / "docs/releases" / f"{version}.md" if not notes.is_file(): fail(f"missing docs/releases/{version}.md") body = notes.read_text(encoding="utf-8") for heading in ("What is complete in this beta", "What is NOT complete in this beta", "Compatibility and upgrade notes"): if heading not in body: fail(f"release notes are missing section `{heading}`") readme = (ROOT / "README.md").read_text(encoding="utf-8") if version not in readme: fail("README.md does not mention the current version") for configuration in (".woodpecker/main.yml", ".github/workflows/ci.yml"): text = (ROOT / configuration).read_text(encoding="utf-8") if "tools/release/package.py" not in text: fail(f"{configuration} does not use the deterministic packager") if "tools/release/smoke.py" not in text: fail(f"{configuration} does not run the archive smoke test") ci_docs = (ROOT / "docs/ci.md").read_text(encoding="utf-8") if "NOT RUN" not in ci_docs: fail("docs/ci.md must state the non-gated items") print(f"release-metadata: OK (version {version})") return 0 if __name__ == "__main__": sys.exit(main())