-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquicksauce-lib
304 lines (215 loc) · 5.57 KB
/
quicksauce-lib
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
function loggy {
printf "%5s: %s\n" "${1}" "${2}"
}
function log_error {
loggy "ERROR" "${1}"
}
function log_info {
loggy "INFO" "${1}"
}
function log_warn {
loggy "WARN" "${1}"
}
function log_debug {
[[ ${PARTY_MODE} ]] || return
loggy "DEBUG" "${1}"
}
function log_json_debug {
[[ ${PARTY_MODE} ]] || return
log_json "${1}" "${2}"
}
function log_json {
[[ -z ${2} ]] && fileName=${1} || fileName=${2}
[[ -z ${timeStamp} ]] && timeStamp=$(date +"%Y-%m-%d_%H%M%S_%s")
scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
debugDir="${scriptPath}/.debug/${timeStamp}"
[[ -d ${debugDir} ]] || mkdir -p ${debugDir}
f=$(echo ${debugDir}/${fileName}| tr ' ' '-')
jq <<< ${!1} > "${f}.json"
log_debug "Variable ${1} written file."p
log_cmd_debug "${f}.json"
}
function log_cmd {
printf "\t %s\n" "${1}"
}
function log_cmd_debug {
[[ ${PARTY_MODE} ]] || return
printf "\t %s\n" "${1}"
}
function log_loop {
for i in ${1}
do
printf "\t %s\n" "${i}"
done
}
function party-converter {
# charles session to HAR file
log_info "Party converter is starting."
for fq in data/*/*/*.chls
do
d=$(dirname -- ${fq})
f=$(basename -- ${fq})
ext="${f##*.}"
f="${f%.*}"
har="${d}/${f}.har"
[[ -f ${har} ]] && log_warn "Existing HAR file found. Skipping ${fq}" || run-party-converter ${fq} ${har}
done
log_info "Party converter has finished."
}
function run-party-converter {
source=${1}
target=${2}
log_info "Converting CharlesProxy session to HTTP archive format (HAR). ${source}"
/Applications/Charles.app/Contents/MacOS/Charles convert ${source} ${target}
}
function party-pooper {
log_warn "Stopping all Charles Proxy and Sauce Connect processes."
while [[ $(pkill -x Charles sc) ]]
do
sleep 2
done
log_info "Party clean up is complete."
}
function check_env {
# sauce credentials are used by sauce connect and never read or written to file
envList=${1}
for e in ${envList}
do
[[ -z ${!e} ]] && missing+="${e} "
done
if [ -n "${missing}" ]
then
log_error "Exiting NOTOK. Missing environment variable(s). Please set!"
log_loop "${missing}"
exit 128
fi
}
function check_env_sauce {
#log_info "Checking Sauce Labs environment configuration."
envList="SAUCE_USERNAME
SAUCE_ACCESS_KEY"
check_env "${envList}"
}
function check_env_keystore {
#log_info "Checking keystore environment configuration."
envList="SAUCE_DEMO_KEY_ALIAS
SAUCE_DEMO_STORE_FILE
SAUCE_DEMO_KEY_PASSWORD
SAUCE_DEMO_STORE_PASSWORD"
check_env "${envList}"
}
function check_env_testfairy {
envList="TESTFAIRY_SDK_TOKEN
TESTFAIRY_ACCESS_KEY"
check_env "${envList}"
}
function check_bin {
binList="curl
jq
openssl
keytool
gh"
curl="curl"
jq="jq"
openssl="openssl"
keytool="java"
gh="gh"
missing=""
for b in ${binList}
do
[[ -z $(command -v ${b}) ]] && [[ ! -z ${!b} ]] && missing+="${!b} "
done
[[ -z $(command -v brew) ]] \
&& log_error "Exiting NOTOK. Missing brew. Please review install command below." \
&& log_cmd '/bin/bash -c $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)' && exit 127
if [ -n "${missing}" ]
then
log_error "Exiting NOTOK. Missing binary. Please review install command below."
log_cmd "brew install ${missing}"
exit 127
fi
}
function check_bin_testfairy_upload {
binList="curl
jq"
curl="curl"
jq="jq"
missing=""
for b in ${binList}
do
[[ -z $(command -v ${b}) ]] && [[ ! -z ${!b} ]] && missing+="${!b} "
done
[[ -z $(command -v brew) ]] \
&& log_error "Exiting NOTOK. Missing brew. Please review install command below." \
&& log_cmd '/bin/bash -c $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)' && exit 127
if [ -n "${missing}" ]
then
log_error "Exiting NOTOK. Missing binary. Please review install command below."
log_cmd "brew install ${missing}"
exit 127
fi
}
function convert_keystore {
# convert keystore to github secret
# requires running buildKeystore first
openssl base64 < ${SRSF} |tr -d '\n' |tee ${SRSF}.txt
}
function load_keystore_env {
f="${keystoreFile}.env"
[[ -f "${f}" ]] && source ${f}
}
function accept_android_sdk_licenses {
yes | ~/Library/Android/sdk/cmdline-tools/latest/bin/sdkmanager --licenses
}
function ip_get_details {
myIp=$(curl ifconfig.me)
myIpDetails=$(curl http://ip-api.com/json/${myIp})
}
function check_env_2 {
envList=${1}
optionalWarnOnly=${2}
missing=""
for e in ${envList}
do
[[ -z ${!e} ]] && missing+="${e} "
done
if [ -n "${missing}" ]
then
if [ -z ${optionalWarnOnly} ]
then
log_error "Exiting NOTOK. Missing environment variable(s). Please set!"
log_loop "${missing}"
exit 128
else
log_warn "Optional environment variable(s) not set."
log_loop "${missing}"
fi
fi
}
function check_env_optional {
check_env_2 "${1}" "optional"
}
function check_env_testfairy_upload_v0 {
envList="appVersion
appName
appFile
protoHost
platformName
packageName
uploadSauceStorage
TESTFAIRY_ACCESS_KEY"
envListOptional="releaseNotes
tags
folderName"
check_env "${envList}"
check_env_optional "${envListOptional}"
}
function check_env_testfairy_upload {
envList="TESTFAIRY_ACCESS_KEY"
check_env "${envList}"
}
function json_kv_get {
jq --arg key "${1}" --raw-output '.[$key]' <<< ${appMetaData}
}
[[ -z ${PARTY_MODE} ]] || printf "\n"
log_debug "To exit quicksauce debug unset PARTY_MODE"