From 64ee7df10f00774018178d0f3e14c237947fe227 Mon Sep 17 00:00:00 2001 From: Lex Li Date: Tue, 3 Dec 2024 21:36:14 -0500 Subject: [PATCH] Simplified tag script. --- move-tag.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/move-tag.py b/move-tag.py index 3536ecad..dd653a36 100644 --- a/move-tag.py +++ b/move-tag.py @@ -1,5 +1,6 @@ import subprocess import sys +import re def run_command(command): @@ -29,12 +30,27 @@ def create_and_push_tag(tag, branch): run_command(f"git push origin {tag}") +def get_largest_release_version(): + """Get the largest release version from the branches.""" + branches = run_command("git branch -r") + release_branches = re.findall(r"release-(\d+\.\d+)", branches) + if not release_branches: + print("No release branches found.") + sys.exit(1) + largest_version = max(release_branches, key=lambda v: list(map(int, v.split(".")))) + return largest_version + + def main(): - if len(sys.argv) != 2: - print("Usage: python move-tag.py ") + if len(sys.argv) > 2: + print("Usage: python move-tag.py []") sys.exit(1) - version = sys.argv[1] + if len(sys.argv) == 2: + version = sys.argv[1] + else: + version = get_largest_release_version() + tag = f"v{version}" branch = f"release-{version}"