Skip to content

Commit da60282

Browse files
pb8oroypat
authored andcommitted
test(repo): ensure CHANGELOG.md is valid
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 <[email protected]>
1 parent 68ab56e commit da60282

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10521052
and to run as a daemon.
10531053
- Enabled PATCH operations on `/drives` resources.
10541054

1055-
## Changed
1055+
### Changed
10561056

10571057
- The microVM `id` supplied to the jailer may now contain alphanumeric
10581058
characters and hyphens, up to a maximum length of 64 characters.

tests/integration_tests/style/test_repo.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"""Tests enforcing git repository structure"""
55

6+
import re
67
import subprocess
78
from pathlib import Path
89

@@ -34,3 +35,25 @@ def test_repo_validate_yaml():
3435
if str(path).startswith("../build/"):
3536
continue
3637
yaml.safe_load(path.open(encoding="utf-8"))
38+
39+
40+
def test_repo_validate_changelog():
41+
"""Make sure the CHANGELOG.md file follows the Keep a Changelog format"""
42+
43+
changelog_path = Path("../CHANGELOG.md")
44+
changelog = changelog_path.read_text(encoding="utf-8").splitlines()
45+
errors = []
46+
for lineno, line in enumerate(changelog, start=1):
47+
if line.startswith("## "):
48+
if not re.match(r"^## \[.+\]$", line):
49+
msg = "Level 2 headings (versions) should be wrapped in []"
50+
errors.append((lineno, msg, line))
51+
if line.startswith("### "):
52+
if not re.match(r"^### (Added|Changed|Deprecated|Removed|Fixed)$", line):
53+
msg = "Unknown Level 3 heading"
54+
errors.append((lineno, msg, line))
55+
56+
for lineno, msg, line in errors:
57+
print(msg)
58+
print(f"\t{lineno}:{line}")
59+
assert len(errors) == 0

0 commit comments

Comments
 (0)