-
Notifications
You must be signed in to change notification settings - Fork 2
/
upload.sh
executable file
·305 lines (264 loc) · 14 KB
/
upload.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
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
#!/bin/bash
#
# (Above line comes out when placing in Xcode scheme)
#
############################################################################
# Example of usage in Xcode Bot
############################################################################
# This script was designed to be run from a post integration step of an Xcode
# Bot. Here is an example of how to do this.
#
# PRODUCT_NAME="MyAwesomeApp"
# SRCROOT_MAIN_DIR="my_awesome_app"
# HIPCHAT_ROOM_NAME="MyAwesomeApp Room"
# HIP_CHAT_AUTH_TOKEN="hsishid8ew8yei8yifyri8ysyi"
# GITHUB_ACCOUNT="atljeremy"
# DISTRO_LIST="MyAwesomeApp TestFlight Distro List Name"
# HOCKEYAPP_API_TOKEN="kahsdiuHISUhdsi8sd9oshjh_hskdihsaskdiao98asydhaisuhISL"
# SIGNING_IDENTITY="iPhone Distribution: Jeremy Fox"
# PROVISIONING_PROFILE="52bf378s-ea37-738e-djs9-shdisdisciod8ju"
#
# source "$XCS_SOURCE_DIR/$SRCROOT_MAIN_DIR/upload.sh"
############################################################################
# Configurable Options
############################################################################
############################################################################
# Used to tell the build system if a build should fail if the upload process fails
#
# Set this ENV variable before calling this script or the default value will be used.
REQUIRE_UPLOAD_SUCCESS=${REQUIRE_UPLOAD_SUCCESS:=1}
############################################################################
# Used to tell the build system which HipChat Room should receive build notifications
#
# Set this ENV variable before calling this script or the default value will be used.
HIPCHAT_ROOM_NAME=${HIPCHAT_ROOM_NAME:="NOT_DEFINED"}
############################################################################
# Used to tell this script to notify the HipChat room specified in
# HIPCHAT_ROOM_NAME variable. If NOTIFY_HIPCHAT_ROOM is set to 1 (true) and
# HIPCHAT_ROOM_NAME is not set, the build will fail.
#
# Set this ENV variable before calling this script or the default value will be used.
NOTIFY_HIPCHAT_ROOM=${NOTIFY_HIPCHAT_ROOM:=1}
############################################################################
# Used to tell this script to notify Slack based on the Slack incoming web
# service URL specified in the SLACK_INCOMING_WEBSERVICE_URL.
#
# Set this ENV variable before calling this script or the default value will be used.
NOTIFY_SLACK_ROOM=${NOTIFY_SLACK_ROOM:=1}
############################################################################
# Used to tell this script what Slack incoming web service URL to use for
# sending messages into Slack.
#
# Set this ENV variable before calling this script or the default value will be used.
SLACK_INCOMING_WEBSERVICE_URL=${SLACK_INCOMING_WEBSERVICE_URL:="NOT_DEFINED"}
############################################################################
# Used to tell the build system if members of the HIPCHAT_ROOM_NAME should receive
# a notification when the build system posts a build notificaiton
#
# Set this ENV variable before calling this script or the default value will be used.
POST_NOTIFY=${POST_NOTIFY:=true}
############################################################################
# Used to tell the build system what HipChat Auth Token should be used for requests
# to the HipChat API
#
# Set this ENV variable before calling this script or the default value will be used.
HIP_CHAT_AUTH_TOKEN=${HIP_CHAT_AUTH_TOKEN:="NOT_DEFINED"}
############################################################################
# Used to specify the source control main directory
#
# Set this ENV variable before calling this script.
SRCROOT_MAIN_DIR=${SRCROOT_MAIN_DIR:="$PRODUCT_NAME"}
############################################################################
# Used to specify the Github account in which tags should be sent
#
# Set this ENV variable before calling this script or the default value will be used.
GITHUB_ACCOUNT=${GITHUB_ACCOUNT:="NOT_DEFINED"}
############################################################################
# Set the Enterprise App Store Project ID that these builds should be uploaded to
# This defaults to project ID 24 if not set, which is the "AG Testing" project.
#
# Set this ENV variable before calling this script or the default value will be used.
DISTRO_LIST=${DISTRO_LIST:="All"}
############################################################################
# HockeyApp api token to be used for upload request
#
# Set this ENV variable before calling this script or the default value will be used.
HOCKEYAPP_API_TOKEN=${HOCKEYAPP_API_TOKEN:=""}
############################################################################
# Crashlytics api token to be used for upload request
#
# Set this ENV variable before calling this script or the default value will be used.
CRASHLYTICS_API_TOKEN=${CRASHLYTICS_API_TOKEN:=""}
############################################################################
# Crashlytics build secret to be used for upload request
#
# Set this ENV variable before calling this script or the default value will be used.
CRASHLYTICS_BUILD_SECRET=${CRASHLYTICS_BUILD_SECRET:=""}
############################################################################
# Crashlytics emails to be used for upload request
#
# Set this ENV variable before calling this script or the default value will be used.
CRASHLYTICS_EMAILS=${CRASHLYTICS_EMAILS:=""}
############################################################################
# Crashlytics group aliases to be used for upload request
#
# Set this ENV variable before calling this script or the default value will be used.
CRASHLYTICS_GROUP_ALIASES=${CRASHLYTICS_GROUP_ALIASES:=""}
############################################################################
# Crashlytics.framework path relative to SRCROOT (defined on line 143 *DO
# NOT CHANGE SRCROOT*) to be used for upload request. This is the directory
# that contains the Crashlyitics.framework.
#
# Set this ENV variable before calling this script or the default value will be used.
CRASHLYTICS_FRAMEWORK_DIRECTORY=${CRASHLYTICS_FRAMEWORK_DIRECTORY:=""}
############################################################################
# Signing Certificate used to sign the IPA
#
# Set this ENV variable before calling this script or the default value will be used.
SIGNING_IDENTITY=${SIGNING_IDENTITY:="NOT_DEFINED"}
############################################################################
# Provisioning Profile used to provision the IPA
#
# Set this ENV variable before calling this script or the default value will be used.
PROVISIONING_PROFILE=${PROVISIONING_PROFILE:="NOT_DEFINED"}
############################################################################
# used to tell the build system to create and send a tag into Github
#
# Set this ENV variable before calling this script or the default value will be used.
TAG_BUILD=${TAG_BUILD:=0}
############################################################################
# DO NOT CHANGE ANYTHING BELOW THIS LINE
############################################################################
XCODE_SERVER_DIR="/Library/Developer/XcodeServer"
URL="https://rink.hockeyapp.net/api/2/apps/upload"
PROVISIONING_PROFILE="$XCODE_SERVER_DIR/ProvisioningProfiles/${PROVISIONING_PROFILE}.mobileprovision"
SRCROOT=${SRCROOT:="$XCS_SOURCE_DIR/$SRCROOT_MAIN_DIR/"}
echo "SRCROOT: $SRCROOT"
NOTES=`cd ${SRCROOT}; git log --pretty=format:"%h - %an, %ar : %s" -n 1`
SHA=`cd ${SRCROOT}; git rev-parse HEAD`
DSYM="/tmp/Archive.xcarchive/dSYMs/${PRODUCT_NAME}.app.dSYM"
DSYM_ZIP="${DSYM}.zip"
IPA="/tmp/${PRODUCT_NAME}.ipa"
APP="/tmp/${PRODUCT_NAME}.xcarchive/Products/Applications/${PRODUCT_NAME}.app"
# Clear out any old copies of the Archive
echo "---------------------------------------------------"
echo "Removing old files from /tmp...";
/bin/rm -rf /tmp/Archive.xcarchive*
echo "Done removing old files from /tmp";
echo "---------------------------------------------------"
# Copy over the latest build the bot just created
echo "---------------------------------------------------"
echo "Copying latest app to /tmp/...";
echo "ARCHIVE: $XCS_ARCHIVE"
/bin/cp -Rp "$XCS_ARCHIVE" "/tmp/"
echo "Done copying latest app to /tmp/";
echo "---------------------------------------------------"
# Create the .ipa to be uploaded
echo "---------------------------------------------------"
echo "Creating .ipa for ${PRODUCT_NAME}"
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${APP}" -o "${IPA}" --embed "${PROVISIONING_PROFILE}"
echo "Done with IPA creation."
echo "---------------------------------------------------"
# Create the zipped .dSYM
echo "---------------------------------------------------"
echo "Zipping .dSYM for ${PRODUCT_NAME}"
/bin/rm "${DSYM}.zip"
/usr/bin/zip -r "${DSYM}.zip" "${DSYM}"
echo "Done creating .dSYM for ${PRODUCT_NAME}"
echo "---------------------------------------------------"
# Upload the build
echo "---------------------------------------------------"
echo "Beginning upload with the following params... "
echo "file: ${IPA}"
echo "dsym: ${DSYM_ZIP}"
echo "api_token: ${HOCKEYAPP_API_TOKEN}"
echo "distribution_lists: ${DISTRO_LIST}"
echo "notes: ${NOTES}"
UPLOAD_SUCCESS=0
INSTALL_URL="Unkown"
if [[ -n $HOCKEYAPP_API_TOKEN ]]; then
# HOCKEYAPP_RESPONSE=$(curl "${URL}" --write-out %{http_code} --silent --output /dev/null \
# -F status=2 \
# -F notify=1 \
# -F notes="${NOTES}" \
# -F notes_type=0 \
# -F ipa=@$IPA \
# -F dsym=@$DSYM_ZIP \
# -F commit_sha=$SHA \
# -H "X-HockeyAppToken: ${HOCKEYAPP_API_TOKEN}")
HOCKEYAPP_RESPONSE=$(curl "${URL}" \
-F status=2 \
-F notify=1 \
-F notes="${NOTES}" \
-F notes_type=0 \
-F ipa=@$IPA \
-F dsym=@$DSYM_ZIP \
-F commit_sha=$SHA \
-H "X-HockeyAppToken: ${HOCKEYAPP_API_TOKEN}")
echo Upload API HTTP Response: ${HOCKEYAPP_RESPONSE}
if [ $HOCKEYAPP_RESPONSE ]; then
UPLOAD_SUCCESS=1
INSTALL_URL=$(echo $HOCKEYAPP_RESPONSE | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["public_url"]')
fi
fi
if [[ -n $CRASHLYTICS_API_TOKEN ]]; then
echo $NOTES | tee /tmp/ReleaseNotes.txt
if [[ -n $CRASHLYTICS_EMAILS ]]; then
$CRASHLYTICS_FRAMEWORK_DIRECTORY/Crashlytics.framework/submit $CRASHLYTICS_API_TOKEN $CRASHLYTICS_BUILD_SECRET -ipaPath "$IPA" -emails $CRASHLYTICS_EMAILS -notesPath /tmp/ReleaseNotes.txt -notifications "YES"
elif [[ -n $CRASHLYTICS_GROUP_ALIASES ]]; then
$CRASHLYTICS_FRAMEWORK_DIRECTORY/Crashlytics.framework/submit $CRASHLYTICS_API_TOKEN $CRASHLYTICS_BUILD_SECRET -ipaPath "$IPA" -notesPath /tmp/ReleaseNotes.txt -groupAliases $CRASHLYTICS_GROUP_ALIASES -notifications "YES"
fi
UPLOAD_SUCCESS=1
fi
if [ $UPLOAD_SUCCESS -eq 0 ]; then
if [ $REQUIRE_UPLOAD_SUCCESS -eq 1 ]; then
echo "err: app version not succesfully uploaded."
echo "To ignore this condition and build succesfully, add:"
echo "REQUIRE_UPLOAD_SUCCESS=0"
echo "to the Run Script Build Phase invoking this script."
exit 1
else
echo "err: app version not succesfully uploaded"
echo "ignoring due to REQUIRE_UPLOAD_SUCCESS=0"
fi
else
VERSION_NUMBER=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "${APP}/Info.plist")
BUILD_NUMBER=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "${APP}/Info.plist")
BOT_NAME=$(echo $XCS_BOT_NAME | tr -d [[:space:]])
TAG_NAME="${BOT_NAME}-${VERSION_NUMBER}-${BUILD_NUMBER}"
POST_COLOR=${POST_COLOR:=green}
GITHUB_TAG_URL=""
POST_MESSAGE="<b>$XCS_BOT_NAME Bot:</b> $PRODUCT_NAME $VERSION_NUMBER ($BUILD_NUMBER) is now available! <img src='http://cdn.meme.am/images/50x50/1152667.jpg'> <br/><b>TestFlight Install URL:</b> <a href='$INSTALL_URL'>$INSTALL_URL</a> <br/><b>Build Notes:</b> ${NOTES}"
SLACK_MESSAGE="<https://fabric.io/lawntap/ios/apps/com.lawntap.partner/beta/releases/7914608552dc0eda775fe37b0cf0e06f0d50d606?build_version=$BUILD_NUMBER&display_version=$VERSION_NUMBER|$PRODUCT_NAME $VERSION_NUMBER ($BUILD_NUMBER)> is now available! \nBuild Notes: ${NOTES}"
if [ $TAG_BUILD -eq 1 ]; then
echo "Tagging release as '${TAG_NAME}'"
echo `cd ${SRCROOT}; git tag -a ${TAG_NAME} -m "${TAG_NAME}"`
echo `cd ${SRCROOT}; git push -u --tags`
GITHUB_TAG_URL="https://github.com/$GITHUB_ACCOUNT/$SRCROOT_MAIN_DIR/releases/tag/$TAG_NAME"
POST_MESSAGE="<b>$XCS_BOT_NAME Bot:</b> $PRODUCT_NAME $VERSION_NUMBER ($BUILD_NUMBER) is now available! <img src='http://cdn.meme.am/images/50x50/1152667.jpg'> <br/><b>GitHub Tag:</b> <a href='$GITHUB_TAG_URL'>$GITHUB_TAG_URL</a> <br/><b>TestFlight Install URL:</b> <a href='$INSTALL_URL'>$INSTALL_URL</a> <br/><b>Build Notes:</b> ${NOTES}"
fi
if [ $NOTIFY_HIPCHAT_ROOM -eq 1 ]; then
HIPCHAT_ROOM_NAME=$(perl -MURI::Escape -e 'print uri_escape shift, , q{^A-Za-z0-9\-._~/:}' -- "$HIPCHAT_ROOM_NAME")
if [ ! ${HIPCHAT_ROOM_NAME} ]; then
echo "NOTIFY_HIPCHAT_ROOM is set to 1 (true) but HIPCHAT_ROOM_NAME is not set. Can't notify HipChat of build without a valid HIPCHAT_ROOM_NAME."
exit 1;
else
echo "Posting notification to HipChat room: $HIPCHAT_ROOM_NAME"
echo "With message: $POST_MESSAGE"
HTTP_STATUS=$(curl -H "Content-Type: application/json" -d '{"color":"'"$POST_COLOR"'", "message":"'"$POST_MESSAGE"'", "notify":'"$POST_NOTIFY"'}' "https://api.hipchat.com/v2/room/${HIPCHAT_ROOM_NAME}/notification?auth_token=$HIP_CHAT_AUTH_TOKEN" --write-out %{http_code} --silent --output /dev/null)
echo "Finished notifying HipChat room with response code: $HTTP_STATUS"
fi
fi
if [ $NOTIFY_SLACK_ROOM -eq 1 ]; then
if [ ! $SLACK_INCOMING_WEBSERVICE_URL ]; then
echo "NOTIFY_SLACK_ROOM is set to 1 (true) but SLACK_INCOMING_WEBSERVICE_URL is not set. Can't notify Slack of build without a valid SLACK_INCOMING_WEBSERVICE_URL."
exit 1;
else
echo "Posting notification to Slack using incoming webservice hook URL: $SLACK_INCOMING_WEBSERVICE_URL"
echo "With message: $SLACK_MESSAGE"
HTTP_STATUS=$(curl -H "Content-Type: application/json" -d '{"text": "'"$SLACK_MESSAGE"'","channel": "#general", "username": "buildbot", "icon_emoji": ":leaf:"}' "$SLACK_INCOMING_WEBSERVICE_URL" --write-out %{http_code} --silent --output /dev/null)
echo "Finished notifying Slack room with response code: $HTTP_STATUS"
fi
fi
fi
echo "Upload process complete"