-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck_version_sync.py
More file actions
72 lines (54 loc) · 2.43 KB
/
Copy pathcheck_version_sync.py
File metadata and controls
72 lines (54 loc) · 2.43 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
#!/usr/bin/env python3
"""Assert that .claude-plugin/plugin.json and .claude-plugin/marketplace.json
report the same version for the claude-leverage plugin.
Recent v0.9.x patches were all release-time bookkeeping (literal backticks,
sanitize_int, secret patterns) and manual two-file version bumps are exactly
the kind of thing that drifts silently. This script is intended to run in CI
on every PR and on push to main.
Exit codes:
0 = versions match
1 = mismatch or structural problem (missing file, missing key, etc.)
"""
from __future__ import annotations
import json
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
PLUGIN_JSON = REPO_ROOT / ".claude-plugin" / "plugin.json"
MARKETPLACE_JSON = REPO_ROOT / ".claude-plugin" / "marketplace.json"
PLUGIN_NAME = "claude-leverage"
def fail(msg: str) -> int:
print(f"ERROR: {msg}", file=sys.stderr)
return 1
def main() -> int:
for path in (PLUGIN_JSON, MARKETPLACE_JSON):
if not path.is_file():
return fail(f"missing {path.relative_to(REPO_ROOT)}")
try:
plugin = json.loads(PLUGIN_JSON.read_text(encoding="utf-8"))
marketplace = json.loads(MARKETPLACE_JSON.read_text(encoding="utf-8"))
except json.JSONDecodeError as e:
return fail(f"invalid JSON: {e}")
plugin_version = plugin.get("version")
if not isinstance(plugin_version, str) or not plugin_version:
return fail("plugin.json: missing or non-string 'version'")
plugins = marketplace.get("plugins")
if not isinstance(plugins, list):
return fail("marketplace.json: 'plugins' must be a list")
entries = [p for p in plugins if isinstance(p, dict) and p.get("name") == PLUGIN_NAME]
if not entries:
return fail(f"marketplace.json: no entry with name == {PLUGIN_NAME!r}")
if len(entries) > 1:
return fail(f"marketplace.json: multiple entries with name == {PLUGIN_NAME!r}")
marketplace_version = entries[0].get("version")
if not isinstance(marketplace_version, str) or not marketplace_version:
return fail("marketplace.json: missing or non-string 'version' for claude-leverage")
if plugin_version != marketplace_version:
return fail(
f"version mismatch: plugin.json={plugin_version!r}, "
f"marketplace.json={marketplace_version!r}"
)
print(f"OK: versions in sync ({plugin_version})")
return 0
if __name__ == "__main__":
sys.exit(main())