Skip to content

Commit

Permalink
changes to the script to take all files at once
Browse files Browse the repository at this point in the history
  • Loading branch information
aaradhak committed Aug 5, 2024
1 parent 5a66875 commit ea7acb9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 40 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/validate-release-notes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Validate Next Release Notes
run: python ci/check-release-notes.py release-notes/next.yml

- name: Validate Stable Release Notes
run: python ci/check-release-notes.py release-notes/stable.yml
- name: Validate Testing Release Notes
run: python ci/check-release-notes.py release-notes/testing.yml
- name: Validate Release Notes
run: python ci/check-release-notes.py release-notes/next.yml release-notes/stable.yml release-notes/testing.yml
73 changes: 41 additions & 32 deletions ci/check-release-notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,58 @@
import sys

def validate_release_notes_structure(data, file_name):
valid = True

if not isinstance(data, dict):
print(f"Error: YAML root should be a dictionary in {file_name}.")
return False
valid = False

if 'releases' not in data:
print(f"Error: 'releases' key not found in {file_name}.")
return False
valid = False

if not isinstance(data['releases'], dict):
if not isinstance(data.get('releases'), dict):
print(f"Error: 'releases' key should contain a dictionary in {file_name}.")
return False
valid = False

for release, content in data['releases'].items():
for release, content in data.get('releases', {}).items():
if not re.match(r'^\d+\.\d{8}\.\d+\.\d+$', release):
print(f"Error: Release key '{release}' should follow the pattern 'x.yyyymmdd.n.m' in {file_name}.")
return False
valid = False

release_line = f"{release}:"
if not release_line.endswith(':'):
print(f"Error: Release key '{release}' does not end with a colon ':' in {file_name}.")
return False
valid = False

if not isinstance(content, dict):
print(f"Error: Release {release} should contain a dictionary in {file_name}.")
return False
valid = False

if 'issues' not in content:
print(f"Error: 'issues' key not found for release {release} in {file_name}.")
return False
valid = False

if not isinstance(content['issues'], list):
if not isinstance(content.get('issues'), list):
print(f"Error: 'issues' key for release {release} should contain a list in {file_name}.")
return False
valid = False

for issue in content['issues']:
for issue in content.get('issues', []):
if not isinstance(issue, dict):
print(f"Error: Each issue for release {release} should be a dictionary in {file_name}.")
return False
valid = False

if 'text' not in issue:
print(f"Error: 'text' key not found in issue for release {release} in {file_name}.")
return False
valid = False
if 'url' not in issue:
print(f"Error: 'url' key not found in issue for release {release} in {file_name}.")
return False
valid = False

return True
return valid

def validate_indentation(file_path):
valid = True
with open(file_path, 'r') as file:
lines = file.readlines()

Expand All @@ -63,29 +66,35 @@ def validate_indentation(file_path):
stripped_line = line.lstrip()
if stripped_line and (len(line) - len(stripped_line)) % indent_size != 0:
print(f"Error: Incorrect indentation at line {i + 1} in {file_path}: '{line.strip()}'")
return False
return True
valid = False
return valid

def main():
parser = argparse.ArgumentParser(description='Validate release notes YAML files.')
parser.add_argument('path', help='path to release notes yaml file')
parser.add_argument('paths', nargs='+', help='paths to YAML files')
args = parser.parse_args()

yaml_file = args.path
try:
with open(yaml_file, 'r') as file:
data = yaml.safe_load(file)
except Exception as e:
print(f"Error loading YAML file {yaml_file}: {e}")
sys.exit(1)
all_valid = True

if not validate_release_notes_structure(data, yaml_file):
sys.exit(1)
for yaml_file in args.paths:
try:
with open(yaml_file, 'r') as file:
data = yaml.safe_load(file)
except Exception as e:
print(f"Error loading YAML file {yaml_file}: {e}")
all_valid = False
continue

if not validate_indentation(yaml_file):
sys.exit(1)
if not validate_release_notes_structure(data, yaml_file):
all_valid = False

if not validate_indentation(yaml_file):
all_valid = False

print(f"Validation successful for {yaml_file}.")
if all_valid:
print("Validation successful for all files.")
else:
sys.exit(1)

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion release-notes/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ releases:
40.20240701.2.0:
issues:
- text: "CVE-2024-6387: OpenSSH 9.8: regreSSHion: RCE in OpenSSH's server, on glibc-based Linux systems"
asurl: "https://github.com/coreos/fedora-coreos-tracker/issues/1754"
url: "https://github.com/coreos/fedora-coreos-tracker/issues/1754"
- text: "Trigger a bootupd update before landing latest 6.9 kernel update in Fedora CoreOS"
url: "https://github.com/coreos/fedora-coreos-tracker/issues/1752"
- text: "qed firmware missing from 40.20240519.3.0"
Expand Down

0 comments on commit ea7acb9

Please sign in to comment.