Skip to content

Commit

Permalink
Harden the collect_changes script
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
mdellweg committed Mar 21, 2024
1 parent 24de2b1 commit 8700c1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions templates/github/.ci/scripts/collect_changes.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import re

import toml
from git import GitCommandError, Repo
from pkg_resources import parse_version
from packaging.version import parse as parse_version

# Read Towncrier settings
tc_settings = toml.load("pyproject.toml")["tool"]["towncrier"]
Expand All @@ -23,15 +23,20 @@ START_STRING = tc_settings.get(
TITLE_FORMAT = tc_settings.get("title_format", "{name} {version} ({project_date})")


# Build a regex to find the header of a changelog section.
# It must have a single capture group to single out the version.
# see help(re.split) for more info.
NAME_REGEX = r".*"
VERSION_REGEX = r"([0-9]+\.[0-9]+\.[0-9][0-9ab]*)"
VERSION_REGEX = r"[0-9]+\.[0-9]+\.[0-9][0-9ab]*"
VERSION_CAPTURE_REGEX = rf"({VERSION_REGEX})"
DATE_REGEX = r"[0-9]{4}-[0-9]{2}-[0-9]{2}"
TITLE_REGEX = (
"("
+ re.escape(
TITLE_FORMAT.format(name="NAME_REGEX", version="VERSION_REGEX", project_date="DATE_REGEX")
)
.replace("NAME_REGEX", NAME_REGEX)
.replace("VERSION_REGEX", VERSION_CAPTURE_REGEX, 1)
.replace("VERSION_REGEX", VERSION_REGEX)
.replace("DATE_REGEX", DATE_REGEX)
+ ")"
Expand Down
2 changes: 1 addition & 1 deletion templates/github/.github/workflows/nightly.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

{{ setup_python(pyversion="3.11") | indent(6) }}

{{ install_python_deps(["gitpython", "toml"]) | indent(6) }}
{{ install_python_deps(["gitpython", "packaging", "toml"]) | indent(6) }}

{{ configure_git() | indent(6) }}

Expand Down

0 comments on commit 8700c1c

Please sign in to comment.