Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .ci/scripts/check_changelog_snippets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/env python3
# /// script
# requires-python = ">=3.11"
# dependencies = [
# ]
# ///
import re
import sys
import tomllib
from pathlib import Path

EXCEPTIONS = [
".TEMPLATE.md",
".gitkeep",
".gitignore",
"pulp_python",
]


def snippet_valid(path: Path, changelog_exts: list[str]) -> bool:
return (path.name in EXCEPTIONS) or (
path.suffix in changelog_exts
and (path.stem.startswith("+") or re.fullmatch(r"\d*", path.stem))
)


if __name__ == "__main__":
with Path("pyproject.toml").open("rb") as fp:
pyproject_toml = tomllib.load(fp)
try:
changelog_exts = [
f".{item['directory']}" for item in pyproject_toml["tool"]["towncrier"]["type"]
]
except KeyError:
changelog_exts = [".feature", ".bugfix", ".doc", ".removal", ".misc"]
matches = Path("CHANGES").rglob("*")
invalid_snippets = ", ".join(f"'{s}'" for s in matches if not snippet_valid(s, changelog_exts))
if invalid_snippets:
sys.exit(f"LINT: Invalid changelog entries: {invalid_snippets}.")
4 changes: 4 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ jobs:
run: |
ruff check

- name: "Check Changelog Snippets"
run: |
uv run .ci/scripts/check_changelog_snippets.py

- name: "Run extra lint checks"
run: |
[ ! -x .ci/scripts/extra_linting.sh ] || .ci/scripts/extra_linting.sh
Expand Down
Loading