From 033f882dcaf5978864c6092c4b245088fa92e773 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 25 May 2024 09:04:41 +0200 Subject: [PATCH] Omit day if possible --- tagger | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tagger b/tagger index 917fa8f..4bb2c90 100755 --- a/tagger +++ b/tagger @@ -7,6 +7,7 @@ import subprocess ap = argparse.ArgumentParser() ap.add_argument("--fullyear", action="store_true") +ap.add_argument("--day-always", action="store_true") ap.add_argument("--prefix", default="r") ap.add_argument("--noop", action="store_true") args = ap.parse_args() @@ -36,20 +37,29 @@ for ln in result.stdout.split("\n"): print(need_tag, found_tags) if need_tag: today = datetime.date.today() + version = [] if args.fullyear: - tag = args.prefix + today.strftime("%Y.%m.%d") + version.append(today.strftime("%Y")) else: year = today.year for m in (10, 100, 1000, 10000): if year % m >= max_major: major = str(year % m) break - tag = args.prefix + major + today.strftime(".%m.%d") + version.append(major) + version.append(today.strftime("%m")) + if args.day_always: + version.append(today.strftime("%d")) + else: + tag = args.prefix + ".".join(version) + if any(t.startswith(tag) for t in found_tags): + version.append(today.strftime("%d")) + tag = args.prefix + ".".join(version) if tag in found_tags: - inc = 1 - while f"{tag}.{inc}" in found_tags: - inc += 1 - tag = f"{tag}.{inc}" + version.append("1") + while args.prefix + ".".join(version) in found_tags: + version[-1] = str(int(version[-1]) + 1) + tag = args.prefix + ".".join(version) print(tag) if not args.noop: subprocess.run(["git", "tag", "-a", tag, "-m", "auto-tagged"])