Skript pro ziskani verze z gitu
This commit is contained in:
parent
bef0c335a1
commit
7d047e934e
36
gitrev.py
Normal file
36
gitrev.py
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
""" Automaticky generator cisla verze
|
||||
Automaticky generuje cislo verze z informaci, poskytnutych gitem
|
||||
Copyright (c) 2019, 2020, 2021 xPablo.cz
|
||||
Autor: Pavel Brychta
|
||||
|
||||
"""
|
||||
import subprocess
|
||||
|
||||
dirty = False
|
||||
branch = "HEAD"
|
||||
build = "0"
|
||||
try:
|
||||
version_parts = subprocess.check_output(["git", "describe", "--tags", "--dirty", "--long", "--always"]).decode().strip().split('-')
|
||||
branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).decode().strip()
|
||||
if version_parts[-1] == "dirty":
|
||||
dirty = True
|
||||
version_parts.pop()
|
||||
|
||||
if len(version_parts) >= 3:
|
||||
# zahodime abbrev
|
||||
version_parts.pop();
|
||||
build = version_parts.pop()
|
||||
version = '-'.join(version_parts)
|
||||
else:
|
||||
# neni zatim zadny tag
|
||||
version = '0.0.0'
|
||||
build = subprocess.check_output(["git", "rev-list", "--all", "--count"]).decode().strip()
|
||||
except:
|
||||
version = 'x.x.x'
|
||||
|
||||
build = "" if build == "0" else "." + build
|
||||
dirty_text = "" if not dirty else "m"
|
||||
branch_text = "" if branch in ("master", "HEAD") else "[{}]".format(branch)
|
||||
|
||||
print("{}{}{}{}".format(version, build, dirty_text, branch_text))
|
Loading…
Reference in New Issue
Block a user