-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump_version.py
74 lines (55 loc) · 2.59 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
#!/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 = "TemplateProject"
PROJECT_SCRIPTS = 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()
else:
newVersionInfo = currentVersionInfo
else:
print("Please supply an argument major, minor or patch")
exit()
newVersionInt = (newVersionInfo.major << 16 & 0xFFFF0000) + (newVersionInfo.minor << 8 & 0x0000FF00) + (newVersionInfo.patch & 0x000000FF)
replacestrs(PROJECT_ROOT + "/config.h", '#define PLUG_VERSION_STR "' + versionStr + '"', '#define PLUG_VERSION_STR "' + str(newVersionInfo) + '"')
replacestrs(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 " + PROJECT_ROOT + "/installer/changelog.txt")
print("\n\n--------------------")
edit = input("\nEdit changelog? Y/N: ")
if edit == 'y' or edit == 'Y':
os.system("vim " + PROJECT_ROOT + "/installer/changelog.txt")
print("\nNew changelog: \n--------------------")
os.system("cat " + PROJECT_ROOT + "/installer/changelog.txt")
print("\n\n--------------------");
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 v" + str(newVersionInfo))
os.system("git push && git push --tags")
if __name__ == '__main__':
main()