Omit day if possible

This commit is contained in:
Peter J. Holzer 2024-05-25 09:04:41 +02:00
parent 96c9d52afd
commit 033f882dca
1 changed files with 16 additions and 6 deletions

22
tagger
View File

@ -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"])