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

(feat): restrict release branches in automation #1765

Merged
merged 8 commits into from
Nov 18, 2024
20 changes: 20 additions & 0 deletions ci/scripts/towncrier_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import argparse
import re
import subprocess
from typing import TYPE_CHECKING

Expand All @@ -16,6 +17,14 @@ class Args(argparse.Namespace):
dry_run: bool


class NoPatchReleaseOnMainError(Exception):
pass


class NoMinorMajorReleaseOffMainError(Exception):
pass
flying-sheep marked this conversation as resolved.
Show resolved Hide resolved


def parse_args(argv: Sequence[str] | None = None) -> Args:
parser = argparse.ArgumentParser(
prog="towncrier-automation",
Expand Down Expand Up @@ -62,6 +71,17 @@ def main(argv: Sequence[str] | None = None) -> None:
text=True,
check=True,
).stdout.strip()
patch_branch_pattern = r"\d+\.\d+\.x"
if Version(args.version).micro != 0 and not re.fullmatch(
patch_branch_pattern, base_branch
):
msg = f"Version {args.version} is a patch release, but "
"you are trying to release from a non-patch release branch: {base_branch}."
flying-sheep marked this conversation as resolved.
Show resolved Hide resolved
raise NoPatchReleaseOnMainError(msg)
if Version(args.version).micro == 0 and base_branch != "main":
msg = f"Version {args.version} is a minor or major release, "
"but you are trying to release not from main: {base_branch}."
raise NoMinorMajorReleaseOffMainError(msg)
pr_description = "" if base_branch == "main" else "@meeseeksdev backport to main"
branch_name = f"release_notes_{args.version}"

Expand Down