Extract release version number from tag, if applicable

This commit is contained in:
Scott Bezek
2022-03-14 21:59:03 -07:00
parent 916854c611
commit 1f7bf8a92a
7 changed files with 54 additions and 28 deletions

View File

@@ -30,3 +30,19 @@ def git_date(short=True):
return iso
except Exception:
raise RuntimeError("Could not read git commit date. Make sure you have git installed and you're working with a git clone of the repository.")
def git_release_version(search_prefix):
try:
tags = subprocess.check_output([
'git',
'tag',
'--points-at',
'HEAD',
]).decode('utf-8').splitlines()
for tag in tags:
if tag.startswith(search_prefix):
return tag[len(search_prefix):]
return None
except Exception:
raise RuntimeError("Could not read git release tags. Make sure you have git installed and you're working with a git clone of the repository.")