|
13 | 13 | sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8") |
14 | 14 |
|
15 | 15 |
|
16 | | -def validate_mdx(file_path: str, tag: str | None = None) -> list[str]: |
| 16 | +def validate_mdx( |
| 17 | + file_path: str, tag: str | None = None, release_notes: bool = False |
| 18 | +) -> list[str]: |
17 | 19 | """ |
18 | | - Validate an MDX release notes file. |
| 20 | + Validate an MDX file. |
19 | 21 |
|
20 | 22 | Args: |
21 | 23 | file_path: Path to the MDX file |
22 | 24 | tag: Optional release tag to validate against (e.g., 'v0.16.0') |
| 25 | + release_notes: If True, validate release notes specific requirements |
23 | 26 |
|
24 | 27 | Returns: |
25 | 28 | List of validation errors (empty if valid) |
@@ -49,46 +52,56 @@ def validate_mdx(file_path: str, tag: str | None = None) -> list[str]: |
49 | 52 | if "description:" not in frontmatter: |
50 | 53 | errors.append("Missing 'description' in frontmatter") |
51 | 54 |
|
52 | | - # Check title matches tag if provided |
53 | | - if tag: |
| 55 | + # Check title matches tag if provided (release notes only) |
| 56 | + if tag and release_notes: |
54 | 57 | title_match = re.search( |
55 | 58 | r'title:\s*["\']?([^"\'\n]+)["\']?', frontmatter |
56 | 59 | ) |
57 | 60 | if title_match and tag not in title_match.group(1): |
58 | 61 | errors.append(f"Title should contain '{tag}'") |
59 | 62 |
|
60 | | - # Check for required sections |
61 | | - required_sections = ["## Overview", "## What's New", "## Full Changelog"] |
62 | | - for section in required_sections: |
63 | | - if section not in content: |
64 | | - errors.append(f"Missing required section: {section}") |
| 63 | + # Release notes specific checks |
| 64 | + if release_notes: |
| 65 | + required_sections = ["## Overview", "## What's New", "## Full Changelog"] |
| 66 | + for section in required_sections: |
| 67 | + if section not in content: |
| 68 | + errors.append(f"Missing required section: {section}") |
65 | 69 |
|
66 | | - # Check for changelog link |
67 | | - if "github.com/amd/gaia/compare/" not in content: |
68 | | - errors.append("Missing changelog comparison link") |
| 70 | + if "github.com/amd/gaia/compare/" not in content: |
| 71 | + errors.append("Missing changelog comparison link") |
69 | 72 |
|
70 | 73 | return errors |
71 | 74 |
|
72 | 75 |
|
73 | 76 | def main(): |
74 | | - parser = argparse.ArgumentParser(description="Validate MDX release notes files") |
75 | | - parser.add_argument("file", help="Path to the MDX file to validate") |
| 77 | + parser = argparse.ArgumentParser(description="Validate MDX files") |
| 78 | + parser.add_argument("file", nargs="+", help="Path(s) to MDX file(s) to validate") |
76 | 79 | parser.add_argument( |
77 | 80 | "--tag", "-t", help="Release tag to validate against (e.g., v0.16.0)" |
78 | 81 | ) |
| 82 | + parser.add_argument( |
| 83 | + "--release-notes", |
| 84 | + "-r", |
| 85 | + action="store_true", |
| 86 | + help="Enable release notes specific validation", |
| 87 | + ) |
79 | 88 | args = parser.parse_args() |
80 | 89 |
|
81 | | - print(f"Validating {args.file}...") |
82 | | - |
83 | | - errors = validate_mdx(args.file, args.tag) |
84 | | - |
85 | | - if errors: |
86 | | - print("❌ Validation errors:") |
87 | | - for error in errors: |
88 | | - print(f" - {error}") |
| 90 | + all_errors = {} |
| 91 | + for file_path in args.file: |
| 92 | + print(f"Validating {file_path}...") |
| 93 | + errors = validate_mdx(file_path, args.tag, args.release_notes) |
| 94 | + if errors: |
| 95 | + all_errors[file_path] = errors |
| 96 | + |
| 97 | + if all_errors: |
| 98 | + for file_path, errors in all_errors.items(): |
| 99 | + print(f"❌ {file_path}:") |
| 100 | + for error in errors: |
| 101 | + print(f" - {error}") |
89 | 102 | sys.exit(1) |
90 | 103 |
|
91 | | - print("✅ MDX validation passed") |
| 104 | + print(f"✅ {len(args.file)} file(s) validated successfully") |
92 | 105 | sys.exit(0) |
93 | 106 |
|
94 | 107 |
|
|
0 commit comments