返回 CodeWhale
check-bundled-plugin-claims.py
根目录 / scripts / check-bundled-plugin-claims.py
1 #!/usr/bin/env python3
2 """Fail when the changelog describes a bundled plugin we do not ship.
3
4 The 0.10.0 section claimed "The bundled plugin is 0.4.0" and pinned marketplace
5 revision `ca6be22` while the tree actually shipped 0.11.2 at revision
6 d8640b17f275 -- three upstream releases apart, with nothing comparing the prose
7 to the assets. Vendored bundles get bumped by a dependency sweep; the sentence
8 describing them is prose nobody re-reads.
9
10 Checks that every shipped bundled-plugin version, and the first-party
11 marketplace revision, literally appear in CHANGELOG.md. Cheap, offline, and it
12 fails on the bump rather than at release.
13 """
14 from __future__ import annotations
15 import json
16 import sys
17 from pathlib import Path
18
19 ROOT = Path(__file__).resolve().parent.parent
20 CHANGELOG = ROOT / "CHANGELOG.md"
21 MARKETPLACE = ROOT / "crates/tui/assets/first-party-marketplace.json"
22 PLUGIN_DIR = ROOT / "crates/tui/plugins"
23
24
25 def main() -> int:
26 text = CHANGELOG.read_text()
27 problems: list[str] = []
28
29 for manifest in sorted(PLUGIN_DIR.glob("*/plugin.json")):
30 data = json.loads(manifest.read_text())
31 name, version = data.get("name", manifest.parent.name), data.get("version")
32 if not version:
33 continue
34 # Only demand a receipt for a plugin the changelog actually discusses;
35 # a bundle it never mentions is not making a false claim about itself.
36 if name not in text:
37 print(f"note: {name} {version} is bundled but unmentioned in CHANGELOG.md")
38 continue
39 if version not in text:
40 problems.append(
41 f" {name}: ships {version}, but CHANGELOG.md never says {version}"
42 )
43
44 if MARKETPLACE.exists():
45 revision = json.loads(MARKETPLACE.read_text()).get("revision")
46 if revision and revision not in text:
47 short = revision[:7]
48 if short not in text:
49 problems.append(
50 f" first-party marketplace: pinned at {revision}, "
51 "which CHANGELOG.md never names"
52 )
53
54 if problems:
55 print("Bundled-plugin claims are stale:\n")
56 print("\n".join(problems))
57 print(
58 "\nUpdate the prose in CHANGELOG.md to match the shipped assets, or\n"
59 "bump the assets. A version in the changelog is a claim to users."
60 )
61 return 1
62
63 print("Bundled-plugin versions and the marketplace revision match CHANGELOG.md.")
64 return 0
65
66
67 if __name__ == "__main__":
68 raise SystemExit(main())
69
69 lines PYTHON