forked from nums-project/nums
-
Notifications
You must be signed in to change notification settings - Fork 1
/
version-tag.py
executable file
·59 lines (46 loc) · 1.44 KB
/
version-tag.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
import subprocess
from nums.core.version import __version__
def runproc(*args):
print(" ".join(args))
return subprocess.Popen(
args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
def communicate(*args):
p = runproc(*args)
return tuple(map(lambda x: x.decode("utf-8"), p.communicate()))
def execute():
input_handler = input
out, err = communicate("git", "version")
if err:
raise Exception(err)
out, err = communicate("git", "tag")
versions = list(map(lambda x: x.strip("\r"), out.strip("\n\r").split("\n")))
print("")
print("tagged versions:")
for version in versions:
print(version)
print("")
# Prefix versions with "v"
v = "v" + __version__
if v in versions:
r = input_handler("%s already tagged, force update (y/n)?" % v)
if r != "y":
return
out, err = communicate("git", "tag", v, "-f")
print(out)
print(err)
out, err = communicate("git", "push", "--tags", "-f")
print(out)
print(err)
else:
r = input_handler("tag %s (y/n)?" % v)
if r != "y":
return
out, err = communicate("git", "tag", v)
print(out)
print(err)
out, err = communicate("git", "push", "--tags")
print(out)
print(err)
if __name__ == "__main__":
execute()