-
Notifications
You must be signed in to change notification settings - Fork 46
/
upload-dsym.sh
101 lines (82 loc) · 2.02 KB
/
upload-dsym.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
#!/bin/sh
TESTFAIRY_ENDPOINT="https://app.testfairy.com/upload/dsym/"
ZIP=zip
CURL=curl
STAT=stat
DATE=date
log() {
NOW=$($DATE +"%Y-%m-%d %H:%M:%S")
echo "${NOW} ${1}"
}
help() {
echo "Usage: ${0} [-f] TESTFAIRY_API_KEY [-p DSYM_PATH] [-u TESTFAIRY_ENDPOINT]"
exit 1
}
DAEMON=1
if [ "${1}" == "-f" ]; then
DAEMON=0
shift
elif [ "${1}" == "-d" ]; then
# backward compatible when -f was the default
shift
fi
API_KEY="${1}"
if [ ! "${API_KEY}" ]; then
echo "Fatal: No Upload API key provided."
help
fi
DSYM_PATH=${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}
shift
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-u)
TESTFAIRY_ENDPOINT="${2}"
shift
;;
-p)
DSYM_PATH="${2}"
shift
;;
*)
help
;;
esac
shift
done
if [ "${DSYM_PATH}" == "" ] || [ "${DSYM_PATH}" == "/" ] || [ ! -d "${DSYM_PATH}" ]; then
echo "Fatal: No .dSYM folder found at path [${DSYM_PATH}]."
help
fi
if [[ ${TESTFAIRY_ENDPOINT} == "" ]]; then
echo "Fatal: No upload endpoint given."
help
fi
NOW=$($DATE +%s)
TMP_FILENAME="/tmp/${NOW}-${DWARF_DSYM_FILE_NAME}.zip"
# Compress the .dSYM folder into a zip file
log "Compressing .dSYM folder ${DSYM_PATH}"
$ZIP -qrp9 "${TMP_FILENAME}" "${DSYM_PATH}"
FILE_SIZE=$($STAT -f "%z" "${TMP_FILENAME}")
foreground_upload() {
# Upload zipped .dSYM file to TestFairy's servers
STARTED=$($DATE +"%s")
$CURL -s -F api_key="${API_KEY}" -F dsym=@"${1}" -o /dev/null "${TESTFAIRY_ENDPOINT}"
ENDED=$($DATE +"%s")
DIFF=$(expr ${ENDED} - ${STARTED})
log "Symbols uploaded in ${DIFF} seconds"
# Clean up behind
rm -f ${TMP_FILENAME}
}
background_upload() {
sh -c "$CURL -F api_key=\"${API_KEY}\" -F dsym=@\"${1}\" -s -o /dev/null \"${TESTFAIRY_ENDPOINT}\"; rm -f ${TMP_FILENAME};" /dev/null 2>&1 &
}
if [ "$DAEMON" == "0" ]; then
log "Uploading ${FILE_SIZE} bytes to dsym server in foreground"
foreground_upload "${TMP_FILENAME}"
else
log "Uploading ${FILE_SIZE} bytes to dsym server in background"
background_upload "${TMP_FILENAME}"
fi
log "TestFairy .dSYM upload script ends"