From ff5fde488e37b20e7f71d948e7972610fb97065d Mon Sep 17 00:00:00 2001 From: ilan-gold Date: Thu, 14 Nov 2024 10:45:21 +0100 Subject: [PATCH] (fix): use non-release-regex --- ci/scripts/towncrier_automation.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ci/scripts/towncrier_automation.py b/ci/scripts/towncrier_automation.py index 6edc79655..f04aae0ca 100755 --- a/ci/scripts/towncrier_automation.py +++ b/ci/scripts/towncrier_automation.py @@ -2,6 +2,7 @@ from __future__ import annotations import argparse +import re import subprocess from typing import TYPE_CHECKING @@ -20,6 +21,10 @@ class NoPatchReleaseOnMainError(Exception): pass +class NoMinorMajorReleaseOffMainError(Exception): + pass + + def parse_args(argv: Sequence[str] | None = None) -> Args: parser = argparse.ArgumentParser( prog="towncrier-automation", @@ -66,9 +71,16 @@ def main(argv: Sequence[str] | None = None) -> None: text=True, check=True, ).stdout.strip() - if Version(args.version).micro != 0 and base_branch == "main": + patch_branch_pattern = r"\d+\.\d+\.x" + if Version(args.version).micro != 0 and not re.fullmatch( + patch_branch_pattern, base_branch + ): raise NoPatchReleaseOnMainError( - f"Version {args.version} is a patch release, but you are trying to release from main branch." + f"Version {args.version} is a patch release, but you are trying to release from a non-patch release branch: {base_branch}." + ) + if Version(args.version).micro == 0 and base_branch != "main": + raise NoMinorMajorReleaseOffMainError( + f"Version {args.version} is a minor or major release, but you are trying to release not from main: {base_branch}." ) pr_description = ( "" if base_branch == "main" else "@meeseeksmachine backport to main"