Skip to content

Commit 01751d6

Browse files
dstansbyd-v-b
andauthored
Add script to check changelog entries (#3290)
* Add script to check changelog entries Fix formatting * Fix changelog entries --------- Co-authored-by: Davis Bennett <[email protected]>
1 parent 3d07ec5 commit 01751d6

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Check changelog entries
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
check-changelogs:
8+
name: Check changelog entries
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
13+
14+
- name: Install uv
15+
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3
16+
17+
- name: Check changelog entries
18+
run: uv run --no-sync python ci/check_changelog_entries.py
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

ci/check_changelog_entries.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Check changelog entries have the correct filename structure.
3+
"""
4+
5+
import sys
6+
from pathlib import Path
7+
8+
VALID_CHANGELOG_TYPES = ["feature", "bugfix", "doc", "removal", "misc"]
9+
CHANGELOG_DIRECTORY = (Path(__file__).parent.parent / "changes").resolve()
10+
11+
12+
def is_int(s: str) -> bool:
13+
try:
14+
int(s)
15+
except ValueError:
16+
return False
17+
else:
18+
return True
19+
20+
21+
if __name__ == "__main__":
22+
print(f"Looking for changelog entries in {CHANGELOG_DIRECTORY}")
23+
entries = CHANGELOG_DIRECTORY.glob("*")
24+
entries = [e for e in entries if e.name not in [".gitignore", "README.md"]]
25+
print(f"Found {len(entries)} entries")
26+
print()
27+
28+
bad_suffix = [e for e in entries if e.suffix != ".rst"]
29+
bad_issue_no = [e for e in entries if not is_int(e.name.split(".")[0])]
30+
bad_type = [e for e in entries if e.name.split(".")[1] not in VALID_CHANGELOG_TYPES]
31+
32+
if len(bad_suffix) or len(bad_issue_no) or len(bad_type):
33+
if len(bad_suffix):
34+
print("Changelog entries without .rst suffix")
35+
print("-------------------------------------")
36+
print("\n".join([p.name for p in bad_suffix]))
37+
print()
38+
if len(bad_issue_no):
39+
print("Changelog entries without integer issue number")
40+
print("----------------------------------------------")
41+
print("\n".join([p.name for p in bad_issue_no]))
42+
print()
43+
if len(bad_type):
44+
print("Changelog entries without valid type")
45+
print("------------------------------------")
46+
print("\n".join([p.name for p in bad_type]))
47+
print(f"Valid types are: {VALID_CHANGELOG_TYPES}")
48+
print()
49+
sys.exit(1)
50+
51+
sys.exit(0)

0 commit comments

Comments
 (0)