-
Notifications
You must be signed in to change notification settings - Fork 1
/
version.py
executable file
·62 lines (53 loc) · 1.86 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
#!/usr/bin/python
import sys
import os
import re
from os import path
import semver
import subprocess
project = str(sys.argv[1]).replace("src/", "")
testreg = re.compile(r"test", re.IGNORECASE)
projects = [
name
for name in os.listdir("./src")
if path.isdir(path.join(".", "src", name)) and not testreg.search(name)
]
def commit(file, version):
process = subprocess.Popen(["git", "add", file], stdout=subprocess.PIPE)
print(process.communicate())
process = subprocess.Popen(["git", "commit", "-m", version], stdout=subprocess.PIPE)
print(process.communicate())
process = subprocess.Popen(["git", "tag", version], stdout=subprocess.PIPE)
print(process.communicate())
process = subprocess.Popen(["git", "push", "--tags", "origin"], stdout=subprocess.PIPE)
print(process.communicate())
if project in projects:
filepath = path.abspath(path.join(".", "src", project, ".version"))
with open(filepath, "r") as reader:
version = reader.readline()
while True:
opt = input("Action: I̲ncrement Patch; S̲pecify Version;")
if opt == "i" or opt == "s":
break
if opt == "i":
try:
ver = semver.VersionInfo.parse(version)
ver = ver.bump_patch()
print(project, version, "->", str(ver))
with open(filepath, "w") as writer:
writer.write(str(ver))
commit(filepath, str(ver))
except:
pass
if opt == "s":
try:
print("Current Version: ", version)
ver = semver.VersionInfo.parse(input("Enter new semver: "))
print(project, version, "->", str(ver))
with open(filepath, "w") as writer:
writer.write(str(ver))
commit(filepath, str(ver))
except:
pass
else:
raise Exception("project {} not found".format(project))