Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden the collect_changes script #852

Merged
merged 1 commit into from
Mar 21, 2024
Merged
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
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
Loading