forked from conradbez/streamlit-auth0
-
Notifications
You must be signed in to change notification settings - Fork 3
/
version.py
69 lines (60 loc) · 1.56 KB
/
version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#
# To simplify versioning I'm going to do the following:
# * Every merge to main: bump the minor version
# * There will be no "patches".
# * Major version bumps will be a manual commit + tag to main
# main == 1.0, 1.1...
# cg/foo == 1.0.dev<timestamp>
#
import os
import re
import time
from typing import NamedTuple
import subprocess
def exec(cmd, timeout=1):
return subprocess.run(
cmd.split(),
capture_output=True,
text=True,
timeout=timeout,
cwd=os.path.dirname(os.path.realpath(__file__))
)
def git_version():
branch = (
exec("git rev-parse --abbrev-ref HEAD")
.stdout.strip()
.replace("/", ".")
.replace("-", ".")
)
descr = exec("git describe --long").stdout.strip()
ret = re.search(r"(\d+).(\d+)-(\d+)-g([0-9a-zA-Z]+)", descr)
return NamedTuple(
"GitVersion",
[
("major", int),
("minor", int),
("commit", int),
("hash", str),
("branch", str),
],
)(
major=int(ret.group(1)),
minor=int(ret.group(2)),
commit=int(ret.group(3)),
hash=ret.group(4),
branch=branch,
)
def get_version():
gv = git_version()
return (
f"{gv.major}.{gv.minor}"
if gv.branch == "main"
else f"{gv.major}.{gv.minor}.dev{int(time.time())}"
)
def get_next_version():
gv = git_version()
return (
f"{gv.major}.{gv.minor + 1}"
if gv.branch == "main"
else f"{gv.major}.{gv.minor}.dev{int(time.time())}"
)