-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_release.py
189 lines (160 loc) · 6.05 KB
/
create_release.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import os
import shutil
import subprocess
import json
from getpass import getpass
import platform
import sys
import re
keystorePath = "./.secrets/keystore.json"
paths_to_remove = ["/build", "/source", "/CMakeLists.txt", "/create_release.py", "/.git", "/.gitmodules", "/.gitignore", "/.vscode", "/.gitattributes"]
paths_to_include = ["/code", "/data", "/docs", "/help", "/javascript", "/jsui", "/externals", "/media", "/misc", "/patchers", "/extras", "/icon.png", "/license.txt", "/README.md", "/package-info.json"]
externals = []
mac_externals = []
generator = "-G Xcode" if (platform.system() == "Darwin") else ""
def cmake_build():
print("configuring with cmake...")
if (os.path.isdir("./build")):
shutil.rmtree("./build")
os.mkdir("./build")
p = subprocess.Popen(["cmake", "-B./build", "-S.", f'{generator}'])
p.wait()
print("building with cmake...")
p = subprocess.Popen(["cmake", "--build", "build", "--config", "Release"])
p.wait()
print("Build Complete!")
def macos_codesign():
if (platform.system() != "Darwin"):
print("not on mac os and connot sign")
return
macoskey = ""
with open(keystorePath) as keystore:
keys = json.load(keystore)
macoskey = keys["developer_team_code"]
if len(macoskey) <= 0:
print("err: not valid key found")
return
dest = "./externals/grainflowExternals_temp"
archive = "./externals/grainflowExternals"
if os.path.isdir(dest):
shutil.rmtree(dest)
os.mkdir(dest)
externals = os.listdir("./externals")
mac_externals = [ s for s in externals if re.search(r"\.mxo$", s) ]
print(mac_externals)
if (len(mac_externals) <= 0): return
for external in mac_externals:
ex_path = f'./externals/{external}'
cmd = f'sudo codesign -s {macoskey} --options runtime --timestamp --force --deep -f {ex_path}'
p = subprocess.Popen(cmd, shell=True)
p.wait()
shutil.copytree(ex_path, dest + f'/{external}')
print("zipping into archive for submission...")
if os.path.isfile(archive+".zip"):
os.remove(archive+".zip")
shutil.make_archive(archive, "zip", dest)
print("Uploading for approval...")
cmd = f'xcrun notarytool submit {archive}.zip --keychain-profile grainflow'
p = subprocess.Popen(cmd, shell=True)
p.wait()
output, error = p.communicate()
submissionid = input("ID: ")
cmd = f'xcrun notarytool wait --keychain-profile grainflow {submissionid}'
p = subprocess.Popen(cmd, shell=True)
p.wait()
for external in mac_externals:
shutil.rmtree(f'./externals/{external}')
shutil.unpack_archive(archive+".zip", "./externals")
mac_staple()
shutil.rmtree(dest)
os.remove(archive+".zip")
def package_release():
src = "./"
dest = "./release"
archive = "./grainflow"
externals = os.listdir("./externals")
if os.path.isdir(dest):
shutil.rmtree(dest)
if os.path.isfile(archive+".maxpack"):
os.remove(archive+".maxpack")
print("copying all files into release folder")
for p in paths_to_include:
src_path = src+p
dest_path = dest+p
print(f'copying {p}')
if os.path.isdir(src_path):
shutil.copytree(src_path, dest_path)
if os.path.isfile(src_path):
shutil.copy2(src_path, dest_path)
reposition_max_patches(dest, 20,20)
print("zipping...")
shutil.make_archive(archive, 'zip', dest)
os.rename(f"{archive}.zip", f"{archive}.maxpack")
print(f"Created {archive}.maxpack")
print("cleaning up")
shutil.rmtree(dest)
def reposition_max_patches(dir, x, y):
#Reposition all windows
print(f"Repositioning all patcher windows to {x},{y}")
for root, dirs, files in os.walk(dir):
for file in files:
if file.endswith(".maxpat") or file.endswith(".maxhelp"):
path = os.path.join(root, file)
maxfile = open(path)
maxtxt = maxfile.read()
maxfile.close()
maxjson = json.loads(maxtxt)
bounds = maxjson['patcher']['rect']
bounds[0] = x
bounds[1] = y
maxjson['patcher']['rect'] = bounds
maxtxt = json.dumps(maxjson, indent= 4)
os.remove(path)
maxfile = open(path, 'w')
maxfile.write(maxtxt)
maxfile.close()
def mac_staple():
if (platform.system() != "Darwin"): return
externals = os.listdir("./externals")
mac_externals = [ s for s in externals if re.search(r"\.mxo$", s) ]
for external in mac_externals:
cmd = f'xcrun stapler staple ./externals/{external}'
p = subprocess.Popen(cmd, shell=True)
p.wait()
def mac_validate():
if (platform.system() != "Darwin"): return
externals = os.listdir("./externals")
mac_externals = [ s for s in externals if re.search(r"\.mxo$", s) ]
for external in mac_externals:
print(f"===== {external} ======")
cmd = f'codesign -dv --verbose=4 ./externals/{external}'
p = subprocess.Popen(cmd, shell=True)
p.wait()
print("\n")
def main():
args = sys.argv
modes = []
if len(args) > 1:
modes = args[1:]
if ('all' in modes):
cmake_build()
macos_codesign()
package_release()
if ('build' in modes): cmake_build()
if ('sign' in modes): macos_codesign()
if ('staple' in modes): mac_staple()
if('validate' in modes): mac_validate()
if ('pack' in modes): package_release()
if len(args) <= 1:
res = input("Would you like to build for your current platform? (Y/N)" )
if res.lower() == 'y':
cmake_build()
if (platform.system() == "Darwin"):
res = input("Would you like to codesign? (Y/N)" )
if res.lower() == 'y':
macos_codesign()
res = input("Would you like to zip a release package? (Y/N)" )
if res.lower() == 'y':
package_release()
if __name__=="__main__":
main()