diff --git a/.ci/scripts/check_changelog_snippets.py b/.ci/scripts/check_changelog_snippets.py new file mode 100755 index 0000000..e6ce61b --- /dev/null +++ b/.ci/scripts/check_changelog_snippets.py @@ -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_rust", +] + + +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}.") diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 68c9675..db4b662 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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