forked from defold/defold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci.py
487 lines (385 loc) · 17.1 KB
/
ci.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#!/usr/bin/env python
# Copyright 2020 The Defold Foundation
# Licensed under the Defold License version 1.0 (the "License"); you may not use
# this file except in compliance with the License.
#
# You may obtain a copy of the License, together with FAQs at
# https://www.defold.com/license
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
import sys
import subprocess
import platform
import os
import base64
from argparse import ArgumentParser
# The platforms we deploy our editor on
PLATFORMS_DESKTOP = ('x86_64-linux', 'x86_64-win32', 'x86_64-darwin')
def call(args, failonerror = True):
print(args)
process = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, shell = True)
output = ''
while True:
line = process.stdout.readline()
if line != '':
output += line
print(line.rstrip())
else:
break
if process.wait() != 0 and failonerror:
exit(1)
return output
def platform_from_host():
system = platform.system()
if system == "Linux":
return "x86_64-linux"
elif system == "Darwin":
return "x86_64-darwin"
else:
return "x86_64-win32"
def aptget(package):
call("sudo apt-get install -y --no-install-recommends " + package)
def aptfast(package):
call("sudo apt-fast install -y --no-install-recommends " + package)
def choco(package):
call("choco install " + package + " -y")
def mingwget(package):
call("mingw-get install " + package)
def setup_keychain(args):
print("Setting up keychain")
keychain_pass = "foobar"
keychain_name = "defold.keychain"
# create new keychain
print("Creating keychain")
# call("security delete-keychain {}".format(keychain_name))
call("security create-keychain -p {} {}".format(keychain_pass, keychain_name))
# set the new keychain as the default keychain
print("Setting keychain as default")
call("security default-keychain -s {}".format(keychain_name))
# unlock the keychain
print("Unlock keychain")
call("security unlock-keychain -p {} {}".format(keychain_pass, keychain_name))
# decode and import cert to keychain
print("Decoding certificate")
cert_path = os.path.join("ci", "cert.p12")
cert_pass = args.keychain_cert_pass
with open(cert_path, "wb") as file:
file.write(base64.decodestring(args.keychain_cert))
print("Importing certificate")
# -A = allow access to the keychain without warning (https://stackoverflow.com/a/19550453)
call("security import {} -k {} -P {} -A".format(cert_path, keychain_name, cert_pass))
os.remove(cert_path)
# required since macOS Sierra https://stackoverflow.com/a/40039594
call("security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k {} {}".format(keychain_pass, keychain_name))
# prevent the keychain from auto-locking
call("security set-keychain-settings {}".format(keychain_name))
# add the keychain to the keychain search list
call("security list-keychains -d user -s {}".format(keychain_name))
print("Done with keychain setup")
def setup_windows_cert(args):
print("Setting up certificate")
cert_path = os.path.join("ci", "windows_cert.pfx")
with open(cert_path, "wb") as file:
file.write(base64.decodestring(args.windows_cert))
def install(args):
system = platform.system()
print("Installing dependencies for system '%s' " % (system))
if system == "Linux":
# we use apt-fast to speed up apt-get downloads
# https://github.com/ilikenwf/apt-fast
call("sudo add-apt-repository ppa:apt-fast/stable")
call("sudo apt-get update", failonerror=False)
call("echo debconf apt-fast/maxdownloads string 16 | sudo debconf-set-selections")
call("echo debconf apt-fast/dlflag boolean true | sudo debconf-set-selections")
call("echo debconf apt-fast/aptmanager string apt-get | sudo debconf-set-selections")
call("sudo apt-get install -y apt-fast aria2")
call("sudo apt-get install -y software-properties-common")
packages = [
"libssl-dev",
"openssl",
"libtool",
"autoconf",
"automake",
"build-essential",
"uuid-dev",
"libxi-dev",
"libopenal-dev",
"libgl1-mesa-dev",
"libglw1-mesa-dev",
"freeglut3-dev",
"tofrodos",
"tree",
"valgrind",
"lib32z1",
"xvfb"
]
aptfast(" ".join(packages))
elif system == "Darwin":
if args.keychain_cert:
setup_keychain(args)
elif system == "Windows":
if args.windows_cert:
setup_windows_cert(args)
def build_engine(platform, with_valgrind = False, with_asan = False, with_vanilla_lua = False, skip_tests = False, skip_codesign = True, skip_docs = False, skip_builtins = False, archive = False, channel = None):
args = 'python scripts/build.py distclean install_ext'.split()
opts = []
waf_opts = []
opts.append('--platform=%s' % platform)
if platform == 'js-web' or platform == 'wasm-web':
args.append('install_ems')
args.append('build_engine')
if channel:
opts.append('--channel=%s' % channel)
if archive:
args.append('archive_engine')
if skip_codesign:
opts.append('--skip-codesign')
if skip_docs:
opts.append('--skip-docs')
if skip_builtins:
opts.append('--skip-builtins')
if skip_tests:
opts.append('--skip-tests')
waf_opts.append('--skip-build-tests')
if with_valgrind:
waf_opts.append('--with-valgrind')
if with_asan:
waf_opts.append('--with-asan')
if with_vanilla_lua:
waf_opts.append('--use-vanilla-lua')
cmd = ' '.join(args + opts)
# Add arguments to waf after a double-dash
if waf_opts:
cmd += ' -- ' + ' '.join(waf_opts)
call(cmd)
def build_editor2(channel = None, engine_artifacts = None, skip_tests = False):
host_platform = platform_from_host()
if not host_platform in PLATFORMS_DESKTOP:
return
opts = []
if engine_artifacts:
opts.append('--engine-artifacts=%s' % engine_artifacts)
if channel:
opts.append('--channel=%s' % channel)
if skip_tests:
opts.append('--skip-tests')
opts_string = ' '.join(opts)
call('python scripts/build.py distclean install_ext build_editor2 --platform=%s %s' % (host_platform, opts_string))
for platform in PLATFORMS_DESKTOP:
call('python scripts/build.py bundle_editor2 --platform=%s %s' % (platform, opts_string))
def download_editor2(channel = None, platform = None):
if platform is None:
platforms = PLATFORMS_DESKTOP
else:
platforms = [platform]
opts = []
if channel:
opts.append('--channel=%s' % channel)
for platform in platforms:
call('python scripts/build.py download_editor2 --platform=%s %s' % (platform, ' '.join(opts)))
def sign_editor2(platform, windows_cert = None, windows_cert_pass = None):
args = 'python scripts/build.py sign_editor2'.split()
opts = []
opts.append('--platform=%s' % platform)
if windows_cert:
opts.append('--windows-cert="%s"' % windows_cert)
if windows_cert_pass:
opts.append('--windows-cert-pass="%s"' % windows_cert_pass)
cmd = ' '.join(args + opts)
call(cmd)
def notarize_editor2(notarization_username = None, notarization_password = None, notarization_itc_provider = None):
if not notarization_username or not notarization_password:
print("No notarization username or password")
exit(1)
# args = 'python scripts/build.py download_editor2 notarize_editor2 archive_editor2'.split()
args = 'python scripts/build.py notarize_editor2'.split()
opts = []
opts.append('--platform=x86_64-darwin')
opts.append('--notarization-username="%s"' % notarization_username)
opts.append('--notarization-password="%s"' % notarization_password)
if notarization_itc_provider:
opts.append('--notarization-itc-provider="%s"' % notarization_itc_provider)
cmd = ' '.join(args + opts)
call(cmd)
def archive_editor2(channel = None, engine_artifacts = None, platform = None):
if platform is None:
platforms = PLATFORMS_DESKTOP
else:
platforms = [platform]
opts = []
if engine_artifacts:
opts.append('--engine-artifacts=%s' % engine_artifacts)
if channel:
opts.append("--channel=%s" % channel)
opts_string = ' '.join(opts)
for platform in platforms:
call('python scripts/build.py archive_editor2 --platform=%s %s' % (platform, opts_string))
def distclean():
call("python scripts/build.py distclean")
def install_ext(platform = None):
opts = []
if platform:
opts.append('--platform=%s' % platform)
call("python scripts/build.py install_ext %s" % ' '.join(opts))
def build_bob(channel = None, branch = None):
args = "python scripts/build.py install_ext sync_archive build_bob archive_bob".split()
opts = []
if channel:
opts.append("--channel=%s" % channel)
cmd = ' '.join(args + opts)
call(cmd)
def release(channel = None):
args = "python scripts/build.py release".split()
opts = []
if channel:
opts.append("--channel=%s" % channel)
cmd = ' '.join(args + opts)
call(cmd)
def release_to_github_markdown(token = None, repo = None, sha1 = None):
args = "python scripts/build.py release_to_github_markdown".split()
opts = []
if token:
opts.append("--github-token=%s" % token)
if repo:
opts.append("--github-target-repo=%s" % repo)
if sha1:
opts.append("--github-sha1=%s" % sha1)
cmd = ' '.join(args + opts)
call(cmd)
def build_sdk(channel = None):
args = "python scripts/build.py build_sdk".split()
opts = []
if channel:
opts.append("--channel=%s" % channel)
cmd = ' '.join(args + opts)
call(cmd)
def smoke_test():
call('python scripts/build.py distclean install_ext smoke_test')
# https://stackoverflow.com/a/55276236/1266551
def get_branch():
branch = call("git rev-parse --abbrev-ref HEAD").strip()
if branch == "HEAD":
branch = call("git rev-parse HEAD")
return branch
def main(argv):
parser = ArgumentParser()
parser.add_argument('commands', nargs="+", help="The command to execute (engine, build-editor, notarize-editor, archive-editor, bob, sdk, install, smoke)")
parser.add_argument("--platform", dest="platform", help="Platform to build for (when building the engine)")
parser.add_argument("--with-asan", dest="with_asan", action='store_true', help="")
parser.add_argument("--with-valgrind", dest="with_valgrind", action='store_true', help="")
parser.add_argument("--with-vanilla-lua", dest="with_vanilla_lua", action='store_true', help="")
parser.add_argument("--archive", dest="archive", action='store_true', help="Archive engine artifacts to S3")
parser.add_argument("--skip-tests", dest="skip_tests", action='store_true', help="")
parser.add_argument("--skip-builtins", dest="skip_builtins", action='store_true', help="")
parser.add_argument("--skip-docs", dest="skip_docs", action='store_true', help="")
parser.add_argument("--engine-artifacts", dest="engine_artifacts", help="Engine artifacts to include when building the editor")
parser.add_argument("--keychain-cert", dest="keychain_cert", help="Base 64 encoded certificate to import to macOS keychain")
parser.add_argument("--keychain-cert-pass", dest="keychain_cert_pass", help="Password for the certificate to import to macOS keychain")
parser.add_argument("--windows-cert", dest="windows_cert", help="Base 64 encoded Windows certificate (pfx)")
parser.add_argument("--windows-cert-pass", dest="windows_cert_pass", help="Password for the Windows certificate")
parser.add_argument('--notarization-username', dest='notarization_username', help="Username to use when sending the editor for notarization")
parser.add_argument('--notarization-password', dest='notarization_password', help="Password to use when sending the editor for notarization")
parser.add_argument('--notarization-itc-provider', dest='notarization_itc_provider', help="Optional iTunes Connect provider to use when sending the editor for notarization")
parser.add_argument('--github-token', dest='github_token', help='GitHub authentication token when releasing to GitHub')
parser.add_argument('--github-target-repo', dest='github_target_repo', help='GitHub target repo when releasing artefacts')
parser.add_argument('--github-sha1', dest='github_sha1', help='A specific sha1 to use in github operations')
args = parser.parse_args()
platform = args.platform
branch = get_branch()
# configure build flags based on the branch
release_channel = None
skip_editor_tests = False
if branch == "master":
engine_channel = "stable"
editor_channel = "editor-alpha"
release_channel = "editor-stable"
make_release = False
engine_artifacts = args.engine_artifacts or "archived"
elif branch == "beta":
engine_channel = "beta"
editor_channel = "beta"
release_channel = engine_channel
make_release = True
engine_artifacts = args.engine_artifacts or "archived"
elif branch == "dev":
engine_channel = "alpha"
editor_channel = "alpha"
release_channel = engine_channel
make_release = True
engine_artifacts = args.engine_artifacts or "archived"
elif branch == "editor-dev":
engine_channel = None
editor_channel = "editor-alpha"
release_channel = editor_channel
make_release = True
engine_artifacts = args.engine_artifacts
elif branch and branch.startswith("DEFEDIT-"):
engine_channel = None
editor_channel = None
make_release = False
engine_artifacts = args.engine_artifacts or "archived-stable"
else: # engine dev branch
engine_channel = "dev"
editor_channel = None
make_release = False
skip_editor_tests = True
engine_artifacts = args.engine_artifacts or "archived"
print("Using branch={} engine_channel={} editor_channel={} engine_artifacts={}".format(branch, engine_channel, editor_channel, engine_artifacts))
# execute commands
for command in args.commands:
if command == "engine":
if not platform:
raise Exception("No --platform specified.")
build_engine(
platform,
with_valgrind = args.with_valgrind or (branch in [ "master", "beta" ]),
with_asan = args.with_asan,
with_vanilla_lua = args.with_vanilla_lua,
archive = args.archive,
skip_tests = args.skip_tests,
skip_builtins = args.skip_builtins,
skip_docs = args.skip_docs,
channel = engine_channel)
elif command == "build-editor":
build_editor2(channel = editor_channel, engine_artifacts = engine_artifacts, skip_tests = skip_editor_tests)
elif command == "download-editor":
download_editor2(channel = editor_channel, platform = platform)
elif command == "notarize-editor":
notarize_editor2(
notarization_username = args.notarization_username,
notarization_password = args.notarization_password,
notarization_itc_provider = args.notarization_itc_provider)
elif command == "sign-editor":
if not platform:
raise Exception("No --platform specified.")
sign_editor2(platform, windows_cert = args.windows_cert, windows_cert_pass = args.windows_cert_pass)
elif command == "archive-editor":
archive_editor2(channel = editor_channel, engine_artifacts = engine_artifacts, platform = platform)
elif command == "bob":
build_bob(channel = engine_channel, branch = branch)
elif command == "sdk":
build_sdk(channel = engine_channel)
elif command == "smoke":
smoke_test()
elif command == "install":
install(args)
elif command == "install_ext":
install_ext(platform = platform)
elif command == "distclean":
distclean()
elif command == "release":
if make_release:
release(channel = release_channel)
else:
print("Branch '%s' is not configured for automatic release from CI" % branch)
elif command == "release_to_github_markdown":
release_to_github_markdown(token = args.github_token,
repo = args.github_target_repo,
sha1 = args.github_sha1)
else:
print("Unknown command {0}".format(command))
if __name__ == "__main__":
main(sys.argv[1:])