forked from sdatkinson/NeuralAmpModelerPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump_version.py
executable file
·101 lines (76 loc) · 3.27 KB
/
bump_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
# https://semver.org/
# pip3 install semver
import os, sys, shutil, subprocess, glob, fileinput, string
import semver
IPLUG2_ROOT = "iPlug2"
PROJECT_ROOT = "NeuralAmpModeler"
PROJECT_SCRIPTS = os.path.join(PROJECT_ROOT, "scripts")
def replacestrs(filename, s, r):
files = glob.glob(filename)
print("replacing " + s + " with " + r + " in " + filename)
for line in fileinput.input(files, inplace=1):
line = line.replace(s, r)
sys.stdout.write(line)
sys.path.insert(0, os.path.join(os.getcwd(), IPLUG2_ROOT, "Scripts"))
from parse_config import parse_config
def main():
config = parse_config(PROJECT_ROOT)
versionStr = config["FULL_VER_STR"]
currentVersionInfo = semver.VersionInfo.parse(versionStr)
print("current version in config.h: v" + versionStr)
if len(sys.argv) == 2:
if sys.argv[1] == "major":
newVersionInfo = currentVersionInfo.bump_major()
elif sys.argv[1] == "minor":
newVersionInfo = currentVersionInfo.bump_minor()
elif sys.argv[1] == "patch":
newVersionInfo = currentVersionInfo.bump_patch()
elif sys.argv[1] == "none":
newVersionInfo = currentVersionInfo
else:
raise ValueError(f"Unrecognized version bump for '{sys.argv[1]}'")
else:
print("Please supply an argument major, minor or patch")
exit()
newVersionInt = (
(newVersionInfo.major << 16 & 0xFFFF0000)
+ (newVersionInfo.minor << 8 & 0x0000FF00)
+ (newVersionInfo.patch & 0x000000FF)
)
replacestrs(
os.path.join(PROJECT_ROOT, "config.h"),
'#define PLUG_VERSION_STR "' + versionStr + '"',
'#define PLUG_VERSION_STR "' + str(newVersionInfo) + '"',
)
replacestrs(
os.path.join(PROJECT_ROOT, "config.h"),
"#define PLUG_VERSION_HEX " + config["PLUG_VERSION_HEX"],
"#define PLUG_VERSION_HEX " + "0x{:08x}".format(newVersionInt),
)
os.system("cd " + PROJECT_SCRIPTS + "; python3 update_version-mac.py")
os.system("cd " + PROJECT_SCRIPTS + "; python3 update_version-ios.py")
os.system("cd " + PROJECT_SCRIPTS + "; python3 update_installer-win.py 0")
print("\nCurrent changelog: \n--------------------")
os.system("cat " + os.path.join(PROJECT_ROOT, "installer", "changelog.txt"))
print("\n\n--------------------")
edit = input("\nEdit changelog? Y/N: ")
if edit == "y" or edit == "Y":
os.system("vim " + os.path.join(PROJECT_ROOT, "installer", "changelog.txt"))
print("\nNew changelog: \n--------------------")
os.system("cat " + os.path.join(PROJECT_ROOT, "installer", "changelog.txt"))
print("\n\n--------------------")
tagname = f"v{newVersionInfo}"
remove_tag = input(f"\nAttempt to remove existing tag for {tagname}? Y/N: ")
if remove_tag == "y" or remove_tag == "Y":
os.system(f"git tag -d {tagname}")
os.system(f"git push --delete origin {tagname}")
edit = input(
"\nTag version and git push to origin (will prompt for commit message)? Y/N: "
)
if edit == "y" or edit == "Y":
os.system("git commit -a --allow-empty")
os.system("git tag " + tagname)
os.system("git push && git push --tags")
if __name__ == "__main__":
main()