Skip to content

Commit afb290d

Browse files
authored
Add more checks to the changelog validator (#3978)
1 parent e92700f commit afb290d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

.github/scripts/validate-changelog-yaml.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222
2323
Checks:
2424
- File is valid YAML
25+
- All top-level keys are valid (title, type, issues, links, important_notes, modules, authors)
26+
- Deprecated keys (merge_requests, configurations) are not used
2527
- Contains required 'title' field (non-empty string)
2628
- Contains required 'type' field (one of: added, changed, fixed, deprecated, removed, dependency_update, security, other)
2729
- Contains required 'authors' field with at least one author
2830
- Each author has a 'name' field (non-empty string)
31+
- Contains either 'links' or 'issues' field (or both)
32+
- If 'issues' is present, it must be an integer not exceeding 17000
2933
"""
3034

3135
import sys
@@ -35,6 +39,8 @@
3539
def validate_changelog_yaml(file_path):
3640
"""Validate a changelog YAML file."""
3741
valid_types = ['added', 'changed', 'fixed', 'deprecated', 'removed', 'dependency_update', 'security', 'other']
42+
valid_keys = ['title', 'type', 'issues', 'links', 'important_notes', 'modules', 'authors']
43+
deprecated_keys = ['merge_requests', 'configurations']
3844

3945
try:
4046
with open(file_path, 'r', encoding='utf-8') as f:
@@ -45,6 +51,18 @@ def validate_changelog_yaml(file_path):
4551
print(f"::error file={file_path}::File must contain YAML mapping (key-value pairs)")
4652
return False
4753

54+
# Check for invalid top-level keys
55+
for key in data.keys():
56+
if key not in valid_keys and key not in deprecated_keys:
57+
print(f"::error file={file_path}::Invalid top-level key '{key}'. Valid keys are: {', '.join(valid_keys)}")
58+
return False
59+
60+
# Check for deprecated keys
61+
for deprecated_key in deprecated_keys:
62+
if deprecated_key in data:
63+
print(f"::error file={file_path}::Our project does not use the '{deprecated_key}' yaml key, please remove")
64+
return False
65+
4866
# Validate 'title' field
4967
if 'title' not in data or not data['title']:
5068
print(f"::error file={file_path}::Missing or empty 'title' field")
@@ -88,6 +106,20 @@ def validate_changelog_yaml(file_path):
88106
print(f"::error file={file_path}::Author {i} 'name' must be a non-empty string")
89107
return False
90108

109+
# Validate that either 'links' or 'issues' exists (or both)
110+
if 'links' not in data and 'issues' not in data:
111+
print(f"::error file={file_path}::Must contain either 'links' or 'issues' key (or both)")
112+
return False
113+
114+
# Validate 'issues' field if present
115+
if 'issues' in data:
116+
if not isinstance(data['issues'], int):
117+
print(f"::error file={file_path}::Field 'issues' must be an integer")
118+
return False
119+
if data['issues'] > 17000:
120+
print(f"::error file={file_path}::Field 'issues' value {data['issues']} points to a non-existing github PR. Did you intend to reference a JIRA issue, please use 'links'.")
121+
return False
122+
91123
# All validations passed
92124
print(f"✓ {file_path} is valid")
93125
print(f" Title: {data['title']}")

0 commit comments

Comments
 (0)