Compare commits

..

No commits in common. "master" and "r4.02.05" have entirely different histories.

1 changed files with 11 additions and 22 deletions

33
tagger
View File

@ -7,20 +7,20 @@ 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")
ap.add_argument("--force", action="store_true")
args = ap.parse_args()
subprocess.run(["git", "pull"])
result = subprocess.run(["git", "log", "--pretty=format:%H %D", "--all", "--date-order"], stdout=subprocess.PIPE, universal_newlines=True)
result = subprocess.run(["git", "log", "--pretty=format:%H %D", "--date-order"], stdout=subprocess.PIPE, universal_newlines=True)
found_tags = set()
need_tag = False
max_major = 0
for ln in result.stdout.split("\n"):
for tag in re.findall(r"\btag: ([-a-z0-9._]+)", ln):
m = re.match(r"[0-9a-f]+ .*\btag: ([-a-z0-9._]+)", ln)
if m:
tag = m.group(1)
if tag.startswith(args.prefix):
found_tags.add(tag)
try:
@ -34,33 +34,22 @@ for ln in result.stdout.split("\n"):
need_tag = True
print(need_tag, found_tags)
if need_tag or args.force:
if need_tag:
today = datetime.date.today()
version = []
if args.fullyear:
version.append(today.strftime("%Y"))
tag = args.prefix + today.strftime("%Y.%m.%d")
else:
year = today.year
for m in (10, 100, 1000, 10000):
if year % m >= max_major:
major = str(year % m)
break
else:
major = str(year)
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)
tag = args.prefix + major + today.strftime(".%m.%d")
if tag in found_tags:
version.append("1")
while args.prefix + ".".join(version) in found_tags:
version[-1] = str(int(version[-1]) + 1)
tag = args.prefix + ".".join(version)
inc = 1
while f"{tag}.{inc}" in found_tags:
inc += 1
tag = f"{tag}.{inc}"
print(tag)
if not args.noop:
subprocess.run(["git", "tag", "-a", tag, "-m", "auto-tagged"])