Skip to content

Commit

Permalink
test(repo): ensure CHANGELOG.md is valid
Browse files Browse the repository at this point in the history
It is easy to forget to add the brackets when adding a new "Unreleased"
version. Add a simple test to validate this.

Also fix a small issue the test caught.

Signed-off-by: Pablo Barbáchano <pablob@amazon.com>
  • Loading branch information
pb8o authored and roypat committed Dec 8, 2023
1 parent 68ab56e commit da60282
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
and to run as a daemon.
- Enabled PATCH operations on `/drives` resources.

## Changed
### Changed

- The microVM `id` supplied to the jailer may now contain alphanumeric
characters and hyphens, up to a maximum length of 64 characters.
Expand Down
23 changes: 23 additions & 0 deletions tests/integration_tests/style/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

"""Tests enforcing git repository structure"""

import re
import subprocess
from pathlib import Path

Expand Down Expand Up @@ -34,3 +35,25 @@ def test_repo_validate_yaml():
if str(path).startswith("../build/"):
continue
yaml.safe_load(path.open(encoding="utf-8"))


def test_repo_validate_changelog():
"""Make sure the CHANGELOG.md file follows the Keep a Changelog format"""

changelog_path = Path("../CHANGELOG.md")
changelog = changelog_path.read_text(encoding="utf-8").splitlines()
errors = []
for lineno, line in enumerate(changelog, start=1):
if line.startswith("## "):
if not re.match(r"^## \[.+\]$", line):
msg = "Level 2 headings (versions) should be wrapped in []"
errors.append((lineno, msg, line))
if line.startswith("### "):
if not re.match(r"^### (Added|Changed|Deprecated|Removed|Fixed)$", line):
msg = "Unknown Level 3 heading"
errors.append((lineno, msg, line))

for lineno, msg, line in errors:
print(msg)
print(f"\t{lineno}:{line}")
assert len(errors) == 0

0 comments on commit da60282

Please sign in to comment.