This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.py
executable file
·133 lines (115 loc) · 3.89 KB
/
build.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
#!/usr/bin/env python
import json
import subprocess
import os
import datetime
import sys
import plistlib
import urllib
# Helpers
def line():
print "----------------------------------------------------------"
# Get command line argument for config file
config_filename = ""
for arg in sys.argv:
if arg != "build.py":
config_filename = arg.strip()
if config_filename == "":
print "please provide a config file e.g. 'python build.py config.json'"
exit(0)
# Load configuration JSON file
if os.path.exists(config_filename) == 0:
print "config file " + config_filename + " not found"
exit(0)
config_file = open(config_filename)
config_json = json.load(config_file)
config_file.close()
# Extract necessary values
config_app_title = config_json["app_title"]
config_bundle_identifier = config_json["bundle_identifier"]
config_bundle_version = config_json["bundle_version"]
config_configuration = config_json["configuration"]
config_scheme = config_json["scheme"]
config_ipa_filename = config_json["ipa_filename"]
config_s3_bucket_name = config_json["s3_bucket_name"]
config_s3_bucket_url = config_json["s3_bucket_url"]
# Print config values for sanity
line()
print "app title: " + config_app_title
print "bundle identifier: " + config_bundle_identifier
print "bundle version: " + config_bundle_version
print "configuration: " + config_configuration
print "scheme: " + config_scheme
print "ipa filename: " + config_ipa_filename
print "s3 bucket name: " + config_s3_bucket_name
print "s3 bucket url: " + config_s3_bucket_url
# Build ipa
line()
print "building IPA"
build_command = "ipa build --Configuration=" + config_configuration + " --Scheme=" + config_scheme
returncode = subprocess.call(build_command, shell=True)
if returncode != 0:
print "failed to build IPA"
exit(0)
# Move ipa into BUILD folder
line()
print "moving IPA into BUILD folder"
if os.path.isdir("BUILD") == 0 or os.path.exists("BUILD") == 0:
print "could not find BUILD folder, creating one"
os.mkdir("BUILD")
move_command = "cp \"" + config_ipa_filename + "\" BUILD"
returncode = subprocess.call(move_command, shell=True)
if returncode != 0:
print "failed to move IPA into BUILD folder"
exit(0)
# Build Manifest Dictionary
line()
print "writing manifest"
ipa_url = config_s3_bucket_url + urllib.quote(config_ipa_filename)
assets = [{
'kind': 'software-package',
'url': ipa_url
}]
metadata = {
'bundle-identifier': config_bundle_identifier,
'bundle-version': config_bundle_version,
'kind': 'software',
'title': config_app_title
}
manifest = {'items': [{'assets': assets, 'metadata': metadata}]}
# Write Manifest to output folder
try:
filename = "BUILD/manifest.plist"
o = open(filename, "wb")
plistlib.writePlist(manifest, o)
o.close()
except:
print("failed to write manifest")
exit(0)
# Build download page
line()
print "writing download page"
try:
manifest_url = config_s3_bucket_url + "manifest.plist"
formatted_environment = "Build Configuration: " + config_configuration
formatted_app_name = config_app_title + " " + config_bundle_version
formatted_title = config_app_title + " - " + config_configuration
formatted_date = "Last Updated: " + str(datetime.datetime.now())
new_page = open("tokenized-download-page.html").read()
new_page = new_page.replace("APP_NAME_KEY", formatted_app_name)
new_page = new_page.replace("URL_KEY", manifest_url)
new_page = new_page.replace("LAST_UPDATED_KEY", formatted_date)
new_page = new_page.replace("PAGE_TITLE_KEY", formatted_title)
# Write new download page
filename = "BUILD/index.html"
o = open(filename, "wb")
o.write(new_page)
o.close()
except:
print("failed to create download page")
exit(0)
# Deploy to Amazon S3
line()
print "deploying to S3"
deploy_command = "aws s3 sync BUILD/ s3://" + config_s3_bucket_name + "/ --profile personal"
subprocess.call(deploy_command, shell=True)