-
Notifications
You must be signed in to change notification settings - Fork 5
/
publishbuild.sh
executable file
·262 lines (202 loc) · 6.94 KB
/
publishbuild.sh
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
#!/usr/bin/env bash
#---------------------------
# For iOS, this build script assumes that your iOS project
# has a target build scheme that is shared and
# that in your Build Settings, "Code Signing Resource Rules Path"
# is set to $(SDKROOT)/ResourceRules.plist
#---------------------------
EXPECTED_ARGS=2
if [ $# -lt $EXPECTED_ARGS ]
then
echo "Usage: ./publishbuild.sh [platform (optional)] [environment (optional)]"
echo "ex: ./publishbuild.sh ios production"
exit 1
fi
#---------------------------
# Disallow publish if changes are uncommitted
#---------------------------
git update-index -q --ignore-submodules --refresh
err=0
# Disallow unstaged changes in the working tree
if ! git diff-files --quiet --ignore-submodules --
then
echo >&2 "cannot $1: you have unstaged changes."
git diff-files --name-status -r --ignore-submodules -- >&2
err=1
fi
# Disallow uncommitted changes in the index
if ! git diff-index --cached --quiet HEAD --ignore-submodules --
then
echo >&2 "cannot $1: your index contains uncommitted changes."
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
err=1
fi
if [ $err = 1 ]
then
echo >&2 "Please commit or stash them."
exit 1
fi
#---------------------------
#***************************
# App Specific Configuration
#***************************
#---------------------------
grunt shell:setShellVariables
if [ -e ".build-config" ]
then
source ".build-config"
else
echo "variable retrieval failed"
exit 1
fi
shouldGenerateIcons=true
#---------------------------
#***************************
# End App Specific Configuration
#***************************
#---------------------------
#---------------------------
# Get Arguments
#---------------------------
platform="web"
env="production"
if [ "$1" ]
then
platform=$1
fi
if [ "$2" ]
then
env=$2
fi
#---------------------------
# Set Variables
#---------------------------
#General
branchName="$(git rev-parse --abbrev-ref HEAD)"
shortHash="$(git rev-parse --short HEAD)"
hockeyMessage="${appName}-${env}-${branchName}-${shortHash}"
buildString="${shortHash}"
#iOS
buildScheme="${appName}"
archiveFile="${appName}.xcarchive"
appFile="${appName}.app"
ipaFile="${appName}-${shortHash}.ipa"
binaryFileName="${ipaFile}"
releaseFolder="$PWD"
otafile="_source-ota-manifest.plist"
otafiletmp="ota-tmp.plist"
otafileout="${appName}-${shortHash}.plist"
#Android
apkFile="${appName}-${shortHash}.apk"
#web
buildFolder="${appName}-${env}-${branchName}-${shortHash}"
#---------------------------
# generate icons
#---------------------------
if [ $shouldGenerateIcons == true ]
then
./icongen.sh ${appName} ${platform} ${env} ${buildString}
else
echo "Bypassing Icon Gen"
fi
#---------------------------
# Do iOS specific things
#---------------------------
if [ "$platform" == "ios" ]
then
binaryFileName="${ipaFile}"
hockeyAppId="${hockeyAppIdiOS}"
cordova --version
grunt build:$env:ios
#(cd cordova/platforms/ios/ && xcodebuild -scheme "$buildScheme" -sdk iphoneos archive -archivePath "$archiveFile" CODE_SIGN_IDENTITY="$codesignIdentity" PROVISIONING_PROFILE=$appleProvisionId)
(cd cordova/platforms/ios/ && xcodebuild -scheme "$buildScheme" -sdk iphoneos archive -archivePath "$archiveFile")
#(cd cordova/platforms/ios/ && xcrun -sdk iphoneos PackageApplication -v "${archiveFile}/Products/Applications/${appFile}" -o "${releaseFolder}/${ipaFile}" --sign "$codesignIdentity")
(cd cordova/platforms/ios/ && xcrun -sdk iphoneos PackageApplication -v "${archiveFile}/Products/Applications/${appFile}" -o "${releaseFolder}/${ipaFile}")
fi
#---------------------------
# Do Android specific things
#---------------------------
if [ "$platform" == "android" ]
then
binaryFileName="${apkFile}"
hockeyAppId="${hockeyAppIdAndroid}"
(cd cordova/platforms/android/ && android update project -p ./ -t "android-21" -s)
(cd cordova/platforms/android/CordovaLib/ && android update project -p ./ -t "android-21" -s)
#(cd cordova/platforms/android/com.urbanairship.phonegap.PushNotification/SleepIQ-google-play-services/ && android update project -p ./ -t "android-21" -s)
#(cd cordova/platforms/android/com.urbanairship.phonegap.PushNotification/SleepIQ-urbanairship-lib/ && android update project -p ./ -t "android-21" -s)
cordova --version
mkdir -p cordova/platforms/android/assets
grunt build:$env:android
(cd cordova && cordova build android --release)
fi
#---------------------------
# Upload to Hockey App
#---------------------------
if [ "$platform" == "ios" -o "$platform" == "android" ]
then
#---------------------------
# Upload IPA
#---------------------------
resource="/${s3Bucket}/${binaryFileName}"
contentType="application/octet-stream"
dateValue=`date "+%a, %d %h %Y %T %z"`
acl="x-amz-acl:public-read"
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${acl}\n${resource}"
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
curl -X PUT -T "${binaryFileName}" \
-H "Host: ${s3Bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "${acl}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
https://${s3Bucket}.s3.amazonaws.com/${binaryFileName}
#---------------------------
# Update OTA plist
#---------------------------
if [ -e ".build-config" ]
then
source ".build-config"
fi
cp ${otafile} ${otafiletmp}
old="__IPA_FILE__"
new="https:\/\/${s3Bucket}.s3.amazonaws.com\/${binaryFileName}"
sed "s/${old}/${new}/g" ${otafiletmp} > ${otafileout}
mv ${otafileout} ${otafiletmp}
old="__ICON_FILE__"
new="https:\/\/${s3Bucket}.s3.amazonaws.com\/${appName}_icon.png"
sed "s/${old}/${new}/g" ${otafiletmp} > ${otafileout}
mv ${otafileout} ${otafiletmp}
old="__BUNDLE_IDENTIFIER__"
new="${bundleId}"
sed "s/${old}/${new}/g" ${otafiletmp} > ${otafileout}
mv ${otafileout} ${otafiletmp}
old="__BUILD_VERSION__"
new="${timeStampVersionCode}"
sed "s/${old}/${new}/g" ${otafiletmp} > ${otafileout}
mv ${otafileout} ${otafiletmp}
old="__SUBTITLE__"
new="${version} (${timeStampVersionCode})"
sed "s/${old}/${new}/g" ${otafiletmp} > ${otafileout}
mv ${otafileout} ${otafiletmp}
old="__APP_NAME__"
new="${appName}"
sed "s/${old}/${new}/g" ${otafiletmp} > ${otafileout}
rm ${otafiletmp}
#---------------------------
# Upload plist
#---------------------------
resource="/${s3Bucket}/${otafileout}"
contentType="text/xml"
dateValue=`date "+%a, %d %h %Y %T %z"`
acl="x-amz-acl:public-read"
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${acl}\n${resource}"
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
curl -X PUT -T "${otafileout}" \
-H "Host: ${s3Bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "${acl}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
https://${s3Bucket}.s3.amazonaws.com/${otafileout}
fi
git clean -df && git checkout -- .