From e8e649325a781e08a1332d0e5ed76012a201288c Mon Sep 17 00:00:00 2001 From: pulpbot Date: Sun, 18 Oct 2026 02:40:22 +0000 Subject: [PATCH] Update CI files --- .ci/scripts/check_changelog_snippets.py | 39 +++++++++++++++++++++++++ .github/workflows/lint.yml | 4 +++ 2 files changed, 43 insertions(+) create mode 100755 .ci/scripts/check_changelog_snippets.py diff --git a/.ci/scripts/check_changelog_snippets.py b/.ci/scripts/check_changelog_snippets.py new file mode 100755 index 00000000..6fc4051f --- /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_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}.") diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ee9d46da..ecfea839 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