-
Notifications
You must be signed in to change notification settings - Fork 11
/
step.sh
executable file
·505 lines (428 loc) · 18.9 KB
/
step.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
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
#!/bin/bash
THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# load bash utils
source "${THIS_SCRIPT_DIR}/bash_utils/utils.sh"
source "${THIS_SCRIPT_DIR}/bash_utils/formatted_output.sh"
# init / cleanup the formatted output
echo "" > "${formatted_output_file_path}"
# ------------------------------
# --- Utils - CleanUp
is_build_action_success=0
function finalcleanup {
echo "-> finalcleanup"
local fail_msg="$1"
# unset UUID
# rm "${CONFIG_provisioning_profiles_dir}/${PROFILE_UUID}.mobileprovision"
# Keychain have to be removed - it's password protected
# and the password is only available in this step!
keychain_fn "remove"
# # Remove downloaded files
# rm ${CERTIFICATE_PATH}
if [ ${is_build_action_success} -eq 1 ] ; then
# success
write_section_to_formatted_output "# Success"
if [[ "${XCODE_BUILDER_ACTION}" == "build" ]] ; then
echo "export BITRISE_BUILD_STATUS=succeeded" >> ~/.bash_profile
elif [[ "${XCODE_BUILDER_ACTION}" == "analyze" ]] ; then
echo "export BITRISE_ANALYZE_STATUS=succeeded" >> ~/.bash_profile
elif [[ "${XCODE_BUILDER_ACTION}" == "archive" ]] ; then
echo "export BITRISE_ARCHIVE_STATUS=succeeded" >> ~/.bash_profile
elif [[ "${XCODE_BUILDER_ACTION}" == "unittest" ]] ; then
echo "export BITRISE_UNITTEST_STATUS=succeeded" >> ~/.bash_profile
fi
else
# failed
write_section_to_formatted_output "# Error"
if [ ! -z "${fail_msg}" ] ; then
write_section_to_formatted_output "**Error Description**:"
write_section_to_formatted_output "${fail_msg}"
fi
write_section_to_formatted_output "*See the logs for more information*"
if [[ "${XCODE_BUILDER_ACTION}" == "build" ]] ; then
echo "export BITRISE_BUILD_STATUS=failed" >> ~/.bash_profile
elif [[ "${XCODE_BUILDER_ACTION}" == "analyze" ]] ; then
echo "export BITRISE_ANALYZE_STATUS=failed" >> ~/.bash_profile
elif [[ "${XCODE_BUILDER_ACTION}" == "archive" ]] ; then
echo "export BITRISE_ARCHIVE_STATUS=failed" >> ~/.bash_profile
elif [[ "${XCODE_BUILDER_ACTION}" == "unittest" ]] ; then
echo "export BITRISE_UNITTEST_STATUS=failed" >> ~/.bash_profile
fi
fi
}
function CLEANUP_ON_ERROR_FN {
local err_msg="$1"
finalcleanup "${err_msg}"
}
set_error_cleanup_function CLEANUP_ON_ERROR_FN
# ------------------------------
# --- Utils - Keychain
function keychain_fn {
if [[ "$1" == "add" ]] ; then
# LC_ALL: required for tr, for more info: http://unix.stackexchange.com/questions/45404/why-cant-tr-read-from-dev-urandom-on-osx
# export KEYCHAIN_PASSPHRASE="$(cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
# Create the keychain
print_and_do_command_exit_on_error security -v create-keychain -p "${KEYCHAIN_PASSPHRASE}" "${BITRISE_KEYCHAIN}"
# Import to keychain
print_and_do_command_exit_on_error security -v import "${CERTIFICATE_PATH}" -k "${BITRISE_KEYCHAIN}" -P "${XCODE_BUILDER_CERTIFICATE_PASSPHRASE}" -A
# Unlock keychain
print_and_do_command_exit_on_error security -v set-keychain-settings -lut 72000 "${BITRISE_KEYCHAIN}"
print_and_do_command_exit_on_error security -v list-keychains -s "${BITRISE_KEYCHAIN}"
print_and_do_command_exit_on_error security -v list-keychains
print_and_do_command_exit_on_error security -v default-keychain -s "${BITRISE_KEYCHAIN}"
print_and_do_command_exit_on_error security -v unlock-keychain -p "${KEYCHAIN_PASSPHRASE}" "${BITRISE_KEYCHAIN}"
elif [[ "$1" == "remove" ]] ; then
print_and_do_command_exit_on_error security -v delete-keychain "${BITRISE_KEYCHAIN}"
fi
}
# ------------------------------
# --- Configs
CONFIG_provisioning_profiles_dir="${HOME}/Library/MobileDevice/Provisioning Profiles"
CONFIG_tmp_profile_dir="${HOME}/tmp_profiles"
# ------------------------------
# --- Inputs
write_section_to_formatted_output "# Configuration"
# Xcode Action - for backward compatibility
if [ -n "$BITRISE_ACTION_BUILD" ]; then
XCODE_BUILDER_ACTION="build"
elif [ -n "$BITRISE_ACTION_ANALYZE" ]; then
XCODE_BUILDER_ACTION="analyze"
elif [ -n "$BITRISE_ACTION_ARCHIVE" ]; then
XCODE_BUILDER_ACTION="archive"
elif [ -n "$BITRISE_ACTION_UNITTEST" ]; then
XCODE_BUILDER_ACTION="unittest"
fi
echo_string_to_formatted_output "* Action: ${XCODE_BUILDER_ACTION}"
# Project-or-Workspace
if [[ "${XCODE_BUILDER_PROJECT_PATH}" == *".xcodeproj" ]]; then
export CONFIG_xcode_project_action="-project"
elif [[ "${XCODE_BUILDER_PROJECT_PATH}" == *".xcworkspace" ]]; then
export CONFIG_xcode_project_action="-workspace"
else
finalcleanup "Failed to get valid project file (invalid project file): ${XCODE_BUILDER_PROJECT_PATH}"
exit 1
fi
echo "CONFIG_xcode_project_action: ${CONFIG_xcode_project_action}"
# Build Tool
CONFIG_build_tool="${XCODE_BUILDER_BUILD_TOOL}"
echo " [i] Specified Build Tool: ${CONFIG_build_tool}"
if [ -z "${CONFIG_build_tool}" ]; then
CONFIG_build_tool="xcodebuild"
fi
if [[ "${XCODE_BUILDER_ACTION}" == "archive" || "${XCODE_BUILDER_ACTION}" == "unittest" ]] ; then
if [[ "${CONFIG_build_tool}" != "xcodebuild" ]]; then
CONFIG_build_tool="xcodebuild"
echo " [!] Build Tool set to xcodebuild - for Archive and UnitTest actions only xcodebuild is supported!"
fi
fi
echo_string_to_formatted_output "* Build Tool: ${CONFIG_build_tool}"
# Required inputs testing
if [ -z "${XCODE_BUILDER_SCHEME}" ] ; then
finalcleanup "Missing required input: No Scheme defined."
exit 1
else
echo_string_to_formatted_output "* Scheme: ${XCODE_BUILDER_SCHEME}"
fi
if [ -z "${XCODE_BUILDER_PROJECT_ROOT_DIR_PATH}" ] ; then
finalcleanup "Missing required input: No Project-Root-Dir-Path defined."
exit 1
else
echo_string_to_formatted_output "* Project Root Dir Path: ${XCODE_BUILDER_PROJECT_ROOT_DIR_PATH}"
fi
if [ -z "${XCODE_BUILDER_PROJECT_PATH}" ] ; then
finalcleanup "Missing required input: No Project-File-Path defined."
exit 1
else
echo_string_to_formatted_output "* Project File Path (relative to Project Root Dir): ${XCODE_BUILDER_PROJECT_PATH}"
fi
if [ -z "${XCODE_BUILDER_CERTIFICATE_URL}" ] ; then
finalcleanup "Missing required input: No Certificate-URL defined."
exit 1
fi
if [ -z "${XCODE_BUILDER_CERTIFICATES_DIR}" ] ; then
finalcleanup "Missing required input: No Certificate-Directory-Path defined."
exit 1
else
echo_string_to_formatted_output "* Certificate Dir Path: ${XCODE_BUILDER_CERTIFICATES_DIR}"
fi
if [[ "${XCODE_BUILDER_ACTION}" == "archive" ]] ; then
if [ -z "${XCODE_BUILDER_DEPLOY_DIR}" ] ; then
finalcleanup "Missing required input: No Deploy-Directory-Path defined."
exit 1
else
echo_string_to_formatted_output "* Deploy Dir Path: ${XCODE_BUILDER_DEPLOY_DIR}"
fi
fi
#
# Xcode Version
echo " (i) Using Xcode version:"
print_and_do_command_exit_on_error xcodebuild -version
# ------------------------------
# --- Main
# --- Create directory structure
print_and_do_command_exit_on_error mkdir -p "${CONFIG_provisioning_profiles_dir}"
print_and_do_command_exit_on_error mkdir -p "${CONFIG_tmp_profile_dir}"
print_and_do_command_exit_on_error mkdir -p "${XCODE_BUILDER_CERTIFICATES_DIR}"
if [[ "${XCODE_BUILDER_ACTION}" == "archive" ]] ; then
print_and_do_command_exit_on_error mkdir -p "${XCODE_BUILDER_DEPLOY_DIR}"
fi
# --- Switch to project's dir
print_and_do_command cd "${XCODE_BUILDER_PROJECT_ROOT_DIR_PATH}"
fail_if_cmd_error "Failed to switch directory to the Project Root Directory"
projectdir="$(dirname "${XCODE_BUILDER_PROJECT_PATH}")"
projectfile="$(basename "${XCODE_BUILDER_PROJECT_PATH}")"
#
print_and_do_command cd "${projectdir}"
fail_if_cmd_error "Failed to switch to the Project-File's Directory"
if [[ "${XCODE_BUILDER_ACTION}" == "archive" ]] ; then
export ARCHIVE_PATH="${XCODE_BUILDER_DEPLOY_DIR}/${XCODE_BUILDER_SCHEME}.xcarchive"
echo " (i) ARCHIVE_PATH=$ARCHIVE_PATH"
export EXPORT_PATH="${XCODE_BUILDER_DEPLOY_DIR}/${XCODE_BUILDER_SCHEME}"
echo " (i) EXPORT_PATH=$EXPORT_PATH"
export DSYM_ZIP_PATH="${XCODE_BUILDER_DEPLOY_DIR}/${XCODE_BUILDER_SCHEME}.dSYM.zip"
echo " (i) DSYM_ZIP_PATH=$DSYM_ZIP_PATH"
fi
if [[ "${XCODE_BUILDER_ACTION}" == "unittest" ]] ; then
CONFIG_unittest_simulator_name="iPad"
if [ -n "$XCODE_BUILDER_UNITTEST_PLATFORM_NAME" ]; then
CONFIG_unittest_simulator_name="$XCODE_BUILDER_UNITTEST_PLATFORM_NAME"
fi
CONFIG_unittest_device_destination="platform=iOS Simulator,name=${CONFIG_unittest_simulator_name}"
echo " (i) UnitTest Device Destination: ${CONFIG_unittest_device_destination}"
fi
# --- Get certificate
echo "---> Downloading Certificate..."
export CERTIFICATE_PATH="${XCODE_BUILDER_CERTIFICATES_DIR}/Certificate.p12"
print_and_do_command curl -Lfso "${CERTIFICATE_PATH}" "${XCODE_BUILDER_CERTIFICATE_URL}"
cert_curl_result=$?
if [ ${cert_curl_result} -ne 0 ]; then
echo " (i) First download attempt failed - retry..."
sleep 5
print_and_do_command_exit_on_error curl -Lfso "${CERTIFICATE_PATH}" "${XCODE_BUILDER_CERTIFICATE_URL}"
fi
echo "CERTIFICATE_PATH: ${CERTIFICATE_PATH}"
if [[ ! -f "${CERTIFICATE_PATH}" ]]; then
finalcleanup "CERTIFICATE_PATH: File not found - failed to download"
exit 1
else
echo " -> CERTIFICATE_PATH: OK"
fi
# LC_ALL: required for tr, for more info: http://unix.stackexchange.com/questions/45404/why-cant-tr-read-from-dev-urandom-on-osx
keychain_pass="$(cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
export KEYCHAIN_PASSPHRASE="${keychain_pass}"
keychain_fn "add"
# Get identities from certificate
export CERTIFICATE_IDENTITY=$(security find-certificate -a ${BITRISE_KEYCHAIN} | grep -Ei '"labl"<blob>=".*"' | grep -oEi '=".*"' | grep -oEi '[^="]+' | head -n 1)
echo "CERTIFICATE_IDENTITY: $CERTIFICATE_IDENTITY"
# --- Get provisioning profile(s)
xcode_build_param_prov_profile_UUID=""
echo "---> Provisioning Profile handling..."
IFS='|' read -a prov_profile_urls <<< "${XCODE_BUILDER_PROVISION_URL}"
prov_profile_count="${#prov_profile_urls[@]}"
echo " (i) Provided Provisioning Profile count: ${prov_profile_count}"
for idx in "${!prov_profile_urls[@]}"
do
a_profile_url="${prov_profile_urls[idx]}"
echo " -> Downloading Provisioning Profile (${idx}): ${a_profile_url}"
a_prov_profile_tmp_path="${CONFIG_tmp_profile_dir}/profile-${idx}.mobileprovision"
echo " (i) a_prov_profile_tmp_path: ${a_prov_profile_tmp_path}"
print_and_do_command curl -Lfso "${a_prov_profile_tmp_path}" "${a_profile_url}"
prov_profile_curl_result=$?
if [ ${prov_profile_curl_result} -ne 0 ]; then
echo " (i) First download attempt failed - retry..."
sleep 5
print_and_do_command_exit_on_error curl -Lfso "${a_prov_profile_tmp_path}" "${a_profile_url}"
fi
if [[ ! -f "${a_prov_profile_tmp_path}" ]] ; then
finalcleanup "a_prov_profile_tmp_path: File not found - failed to download"
exit 1
fi
# Get UUID & install provisioning profile
a_profile_uuid=$(/usr/libexec/PlistBuddy -c "Print UUID" /dev/stdin <<< $(/usr/bin/security cms -D -i "${a_prov_profile_tmp_path}"))
fail_if_cmd_error "Failed to get UUID from Provisioning Profile: ${a_prov_profile_tmp_path} | Most likely the Certificate can't be used with this Provisioning Profile."
echo " (i) a_profile_uuid: ${a_profile_uuid}"
a_provisioning_profile_file_path="${CONFIG_provisioning_profiles_dir}/${a_profile_uuid}.mobileprovision"
print_and_do_command_exit_on_error mv "${a_prov_profile_tmp_path}" "${a_provisioning_profile_file_path}"
if [[ "${prov_profile_count}" == "1" ]] ; then
# force use it (specify it as a build param)
xcode_build_param_prov_profile_UUID="${a_profile_uuid}"
fi
done
echo " (i) Available Provisioning Profiles:"
print_and_do_command_exit_on_error ls -l "${CONFIG_provisioning_profiles_dir}"
# --- Start the build
if [[ "${XCODE_BUILDER_ACTION}" == "build" ]] ; then
print_and_do_command ${CONFIG_build_tool} \
${CONFIG_xcode_project_action} "${projectfile}" \
-scheme "${XCODE_BUILDER_SCHEME}" \
clean build \
PROVISIONING_PROFILE="${xcode_build_param_prov_profile_UUID}" \
CODE_SIGN_IDENTITY="${CERTIFICATE_IDENTITY}" \
OTHER_CODE_SIGN_FLAGS="--keychain ${BITRISE_KEYCHAIN}"
elif [[ "${XCODE_BUILDER_ACTION}" == "unittest" ]] ; then
#
# OLD METHOD (doesn't work if it runs through SSH)
#
function run_tests {
print_and_do_command ${CONFIG_build_tool} \
${CONFIG_xcode_project_action} "${projectfile}" \
-scheme "${XCODE_BUILDER_SCHEME}" \
clean test \
-destination "${CONFIG_unittest_device_destination}" \
-sdk iphonesimulator \
PROVISIONING_PROFILE="${xcode_build_param_prov_profile_UUID}" \
CODE_SIGN_IDENTITY="${CERTIFICATE_IDENTITY}" \
OTHER_CODE_SIGN_FLAGS="--keychain ${BITRISE_KEYCHAIN}"
}
run_tests
test_run_res=$?
if [ ${test_run_res} -eq 65 ] ; then
echo " * First attempt failed with exit code 65, which might mean that the Simulator was not yet ready (in this case you should see a 'Unable to run app in Simulator' error, printed by Xcode) - retrying..."
run_tests
fi
# ${CONFIG_build_tool} \
# ${CONFIG_xcode_project_action} "${projectfile}" \
# -scheme "${XCODE_BUILDER_SCHEME}" \
# clean test \
# -destination "${CONFIG_unittest_device_destination}" \
# -sdk iphonesimulator \
# CODE_SIGN_IDENTITY="${CERTIFICATE_IDENTITY}" \
# OTHER_CODE_SIGN_FLAGS="--keychain ${BITRISE_KEYCHAIN}"
# #
# # xcuserver based solution (works through SSH)
# #
# export KEYCHAIN_PASSWORD="${KEYCHAIN_PASSPHRASE}"
# export KEYCHAIN_NAME="${BITRISE_KEYCHAIN}"
# export CODE_SIGN_IDENTITY="${CERTIFICATE_IDENTITY}"
# if [ ! -z "${xcode_build_param_prov_profile_UUID}" ] ; then
# export PROVISIONING_PROFILE="${xcode_build_param_prov_profile_UUID}"
# fi
# export BUILD_PROJECTDIR="$(pwd)"
# export BUILD_PROJECTFILE="${projectfile}"
# export BUILD_BUILDTOOL="${CONFIG_build_tool}"
# export BUILD_SCHEME="${XCODE_BUILDER_SCHEME}"
# export BUILD_DEVICENAME="${CONFIG_unittest_simulator_name}"
# print_and_do_command bash "${THIS_SCRIPT_DIR}/xcuserver_utils/run_unit_test_with_xcuserver.sh"
elif [[ "${XCODE_BUILDER_ACTION}" == "analyze" ]] ; then
print_and_do_command ${CONFIG_build_tool} \
${CONFIG_xcode_project_action} "${projectfile}" \
-scheme "${XCODE_BUILDER_SCHEME}" \
clean analyze \
PROVISIONING_PROFILE="${xcode_build_param_prov_profile_UUID}" \
CODE_SIGN_IDENTITY="${CERTIFICATE_IDENTITY}" \
OTHER_CODE_SIGN_FLAGS="--keychain ${BITRISE_KEYCHAIN}"
elif [[ "${XCODE_BUILDER_ACTION}" == "archive" ]] ; then
print_and_do_command ${CONFIG_build_tool} \
${CONFIG_xcode_project_action} "${projectfile}" \
-scheme "${XCODE_BUILDER_SCHEME}" \
clean archive -archivePath "${ARCHIVE_PATH}" \
PROVISIONING_PROFILE="${xcode_build_param_prov_profile_UUID}" \
CODE_SIGN_IDENTITY="${CERTIFICATE_IDENTITY}" \
OTHER_CODE_SIGN_FLAGS="--keychain ${BITRISE_KEYCHAIN}"
fi
build_res_code=$?
echo " (i) build_res_code: ${build_res_code}"
if [ ${build_res_code} -eq 0 ]; then
export XCODEBUILD_STATUS="succeeded"
else
export XCODEBUILD_STATUS="failed"
fi
echo "XCODEBUILD_STATUS: $XCODEBUILD_STATUS"
if [[ "${XCODEBUILD_STATUS}" == "succeeded" ]] ; then
if [[ "${XCODE_BUILDER_ACTION}" == "build" || "${XCODE_BUILDER_ACTION}" == "analyze" || "${XCODE_BUILDER_ACTION}" == "unittest" ]] ; then
# done
is_build_action_success=1
finalcleanup
exit 0
fi
else
finalcleanup "Xcode '${XCODE_BUILDER_ACTION}' Action Failed"
exit 1
fi
#
# --- ARCHIVE specific
# Export ipa if everyting succeeded
if [[ "${XCODE_BUILDER_ACTION}" == "archive" ]] ; then
if [[ "$XCODEBUILD_STATUS" == "succeeded" ]] ; then
# Export ipa
write_section_to_formatted_output "## Generating signed IPA"
# Get the name of the profile
IFS=$'\n'
embedded_mobile_prov_path=""
# We need -maxdepth 2 because of the `*.app` directory
for a_emb_path in $(find "${ARCHIVE_PATH}/Products/Applications" -type f -maxdepth 2 -ipath '*.app/embedded.mobileprovision')
do
echo " * embedded.mobileprovision: ${a_emb_path}"
if [ ! -z "${embedded_mobile_prov_path}" ] ; then
finalcleanup "More than one \`embedded.mobileprovision\` found in \`${ARCHIVE_PATH}/Products/Applications/*.app\`"
exit 1
fi
embedded_mobile_prov_path="${a_emb_path}"
done
unset IFS
if [ -z "${embedded_mobile_prov_path}" ] ; then
finalcleanup "No \`embedded.mobileprovision\` found in \`${ARCHIVE_PATH}/Products/Applications/*.app\`"
exit 1
fi
profile_name=`/usr/libexec/PlistBuddy -c 'Print :Name' /dev/stdin <<< $(security cms -D -i "${embedded_mobile_prov_path}")`
fail_if_cmd_error "Missing embedded mobileprovision in xcarchive"
echo " (i) Found Profile Name, for signing: ${profile_name}"
print_and_do_command xcodebuild \
-exportArchive \
-exportFormat ipa \
-archivePath "${ARCHIVE_PATH}" \
-exportPath "${EXPORT_PATH}" \
-exportProvisioningProfile "${profile_name}"
fail_if_cmd_error "Xcode Export Archive action failed!"
echo_string_to_formatted_output "* Archive build success"
echo "export BITRISE_IPA_PATH='${EXPORT_PATH}.ipa'" >> ~/.bash_profile
echo_string_to_formatted_output "* .IPA path: ${EXPORT_PATH}.ipa"
# get the .app.dSYM folders from the dSYMs archive folder
archive_dsyms_folder="${ARCHIVE_PATH}/dSYMs"
print_and_do_command ls "${archive_dsyms_folder}"
app_dsym_count=0
app_dsym_path=""
IFS=$'\n'
for a_app_dsym in $(find "${archive_dsyms_folder}" -type d -name "*.app.dSYM") ; do
echo " (i) .app.dSYM found: ${a_app_dsym}"
app_dsym_count=$[app_dsym_count + 1]
app_dsym_path="${a_app_dsym}"
echo " (i) app_dsym_count: $app_dsym_count"
done
unset IFS
echo " (i) Found dSYM count: ${app_dsym_count}"
if [ ${app_dsym_count} -eq 1 ] ; then
echo_string_to_formatted_output "* dSYM found at: ${app_dsym_path}"
if [ -d "${app_dsym_path}" ] ; then
export DSYM_PATH="${app_dsym_path}"
else
echo_string_to_formatted_output "* (i) *Found dSYM path is not a directory!*"
fi
else
if [ ${app_dsym_count} -eq 0 ] ; then
echo_string_to_formatted_output "* (i) **No dSYM found!** To generate debug symbols (dSYM) go to your Xcode Project's Settings - *Build Settings - Debug Information Format* and set it to *DWARF with dSYM File*."
else
echo_string_to_formatted_output "* (i) *More than one dSYM found!*"
fi
fi
# Generate dSym zip
if [[ ! -z "${DSYM_PATH}" && -d "${DSYM_PATH}" ]] ; then
echo "Generating zip for dSym"
(
dsym_parent_folder=$( dirname "${DSYM_PATH}" )
dsym_fold_name=$( basename "${DSYM_PATH}" )
# cd into dSYM parent to not to store full
# paths in the ZIP
print_and_do_command_exit_on_error cd "${dsym_parent_folder}"
print_and_do_command_exit_on_error /usr/bin/zip -rTy \
"${DSYM_ZIP_PATH}" \
"${dsym_fold_name}"
)
fail_if_cmd_error "Failed to create dSYM ZIP"
echo "export BITRISE_DSYM_PATH='${DSYM_ZIP_PATH}'" >> ~/.bash_profile
is_build_action_success=1
else
is_build_action_success=1
fi
fi
fi
finalcleanup