Tag repo with date

This commit is contained in:
Peter J. Holzer 2022-03-21 12:00:00 +01:00
commit c92864febe
1 changed files with 33 additions and 0 deletions

33
tagger Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/python3
import datetime
import re
import subprocess
subprocess.run(["git", "pull"])
result = subprocess.run(["git", "log", "--pretty=format:%H %D", "--date-order"], stdout=subprocess.PIPE, universal_newlines=True)
found_tags = set()
need_tag = False
for ln in result.stdout.split("\n"):
m = re.match(r"[0-9a-f]+ .*\btag: ([-a-z0-9._]+)", ln)
if m:
found_tags.add(m.group(1))
if not found_tags:
need_tag = True
print(need_tag, found_tags)
if need_tag:
today = datetime.date.today()
tag = today.strftime("r%y.%m.%d")
if tag in found_tags:
inc = 1
while f"{tag}.{inc}" in found_tags:
inc += 1
tag = f"{tag}.{inc}"
print(tag)
subprocess.run(["git", "tag", "-a", tag, "-m", "auto-tagged"])
subprocess.run(["git", "push", "--tags"])
# vim: expandtab sw=4