# SPDX-License-Identifier: MIT """Fail the release check on violations the repository can see. python tools/provenance_check.py Checks, excluding `.git` and caches: - ROM/archive suffixes must not be present; - code files must not carry a GPL/LGPL SPDX header or licence text; - text files must not contain a machine path or the private ROM mirror name; - the project LICENSE must exist. This is a guardrail, not a legal opinion. The source ledger and incidents in docs/provenance.md are the actual record. """ from __future__ import annotations import re import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent ROM_SUFFIXES = {".nes", ".unf", ".fds", ".zip", ".7z", ".bin"} CODE_SUFFIXES = {".py", ".rs", ".c", ".h", ".cpp", ".js", ".ts", ".sh", ".ps1"} GPL_RE = re.compile(r"SPDX-License-Identifier:\s*(GPL|LGPL)|GNU (General|Lesser General) Public License", re.I) PATH_RE = re.compile(r"\b[A-Za-z]:[\\/]|\b10\.10\.10\.10\b") SKIP_DIRS = {".git", "__pycache__", ".pytest_cache", ".ruff_cache", "venv", ".venv"} def main() -> int: issues = [] if not (ROOT / "LICENSE").exists(): issues.append("LICENSE is missing") for path in ROOT.rglob("*"): if not path.is_file() or any(part in SKIP_DIRS for part in path.parts): continue suffix = path.suffix.lower() if suffix in ROM_SUFFIXES: issues.append(f"ROM/archive present: {path.relative_to(ROOT)}") continue try: text = path.read_text(encoding="utf-8", errors="ignore") except OSError: continue if suffix in CODE_SUFFIXES and GPL_RE.search(text): issues.append(f"GPL/LGPL code header: {path.relative_to(ROOT)}") if PATH_RE.search(text): issues.append(f"machine path or private mirror name: {path.relative_to(ROOT)}") if issues: print("provenance check: FAIL") for issue in issues: print(" ", issue) return 1 print("provenance check: pass") return 0 if __name__ == "__main__": sys.exit(main())