1313"""
1414
1515import json
16+ import re
1617import sys
1718import tomllib
1819from pathlib import Path
2122
2223class VersionCheck (NamedTuple ):
2324 """Result of a version check."""
25+
2426 file : str
2527 expected : str
2628 found : str
@@ -74,6 +76,29 @@ def set_marketplace_version(version: str, root: Path) -> None:
7476 f .write ("\n " )
7577
7678
79+ def _read_front_matter_value (path : Path , key : str ) -> str :
80+ """Read a YAML front-matter value from a markdown file."""
81+ content = path .read_text (encoding = "utf-8" )
82+ front_matter_match = re .match (r"^---\s*\n(.*?)\n---\s*\n" , content , re .DOTALL )
83+ if not front_matter_match :
84+ raise ValueError (f"Missing front matter in { path } " )
85+ front_matter = front_matter_match .group (1 )
86+ value_match = re .search (
87+ rf'^{ re .escape (key )} :\s*"([^"]+)"\s*$' ,
88+ front_matter ,
89+ re .MULTILINE ,
90+ )
91+ if not value_match :
92+ raise ValueError (f"Missing { key } in front matter for { path } " )
93+ return value_match .group (1 )
94+
95+
96+ def get_skill_codeguard_version (root : Path ) -> str :
97+ """Get codeguard-version from skills/software-security/SKILL.md."""
98+ skill_path = root / "skills" / "software-security" / "SKILL.md"
99+ return _read_front_matter_value (skill_path , "codeguard-version" )
100+
101+
77102def validate_versions (expected_version : str , root : Path = None ) -> list [VersionCheck ]:
78103 """
79104 Validate all versions match the expected version.
@@ -89,15 +114,24 @@ def validate_versions(expected_version: str, root: Path = None) -> list[VersionC
89114 root = Path (__file__ ).parent .parent
90115
91116 checks = [
92- VersionCheck ("pyproject.toml" , expected_version , get_pyproject_version (root ), False ),
117+ VersionCheck (
118+ "pyproject.toml" , expected_version , get_pyproject_version (root ), False
119+ ),
93120 VersionCheck ("plugin.json" , expected_version , get_plugin_version (root ), False ),
94- VersionCheck ("marketplace.json" , expected_version , get_marketplace_version (root ), False ),
121+ VersionCheck (
122+ "marketplace.json" , expected_version , get_marketplace_version (root ), False
123+ ),
124+ VersionCheck (
125+ "SKILL.md" ,
126+ expected_version ,
127+ get_skill_codeguard_version (root ),
128+ False ,
129+ ),
95130 ]
96131
97132 # Update matches field
98133 return [
99- VersionCheck (c .file , c .expected , c .found , c .expected == c .found )
100- for c in checks
134+ VersionCheck (c .file , c .expected , c .found , c .expected == c .found ) for c in checks
101135 ]
102136
103137
0 commit comments