-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep.sh
More file actions
235 lines (218 loc) · 8.54 KB
/
step.sh
File metadata and controls
235 lines (218 loc) · 8.54 KB
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
#!/bin/sh
# Parse env variables
env_list_parsed=""
if [ -n "$env_list" ]; then
# Convert newline-separated key-value pairs to -e KEY=VALUE format
while IFS='=' read -r key value; do
if [ -n "$key" ]; then
# Append each env var with -e prefix
env_list_parsed="$env_list_parsed -e $key=$value"
fi
done <<< "$env_list"
fi
# Define minimum DCD version
if [ "$use_beta" = "true" ]; then
DCD_VERSION="@devicecloud.dev/dcd@beta"
else
DCD_VERSION="@devicecloud.dev/dcd@>=4.4.0"
fi
# Parse metadata list (similar to env_list)
metadata_parsed=""
if [ -n "$metadata" ]; then
while IFS='=' read -r key value; do
if [ -n "$key" ]; then
metadata_parsed="$metadata_parsed -m $key=$value"
fi
done <<< "$metadata"
fi
# Refine variables
[[ "$async" == "true" ]] && is_async="true"
[[ "$google_play" == "true" ]] && is_google_play="true"
[[ "$ignore_sha_check" == "true" ]] && is_ignore_sha_check="true"
[[ "$show_crosshairs" == "true" ]] && is_show_crosshairs="true"
[[ "$maestro_chrome_onboarding" == "true" ]] && is_maestro_chrome_onboarding="true"
[[ "$android_no_snapshot" == "true" ]] && is_android_no_snapshot="true"
[[ "$debug" == "true" ]] && is_debug="true"
[[ "$json" == "true" ]] && is_json="true"
[[ "$json_file" == "true" ]] && is_json_file="true"
[[ "$dry_run" == "true" ]] && is_dry_run="true"
[[ "$disable_animations" == "true" ]] && is_disable_animations="true"
[[ "$quiet" == "true" ]] && is_quiet="true"
# Change to source directory
cd $BITRISE_SOURCE_DIR
EXIT_CODE=0
# Log all variables for debugging
echo "DCD variables:"
echo "allure_path: $allure_path"
echo "android_api_level: $android_api_level"
echo "android_device: $android_device"
echo "android_no_snapshot: $android_no_snapshot"
echo "api_key: $api_key"
echo "api_url: $api_url"
echo "app_binary_id: $app_binary_id"
echo "app_file: $app_file"
echo "artifacts_path: $artifacts_path"
echo "async: $async"
echo "config: $config"
echo "device_locale: $device_locale"
echo "download_artifacts: $download_artifacts"
echo "dry_run: $dry_run"
echo "env_list: $env_list"
echo "exclude_flows: $exclude_flows"
echo "exclude_tags: $exclude_tags"
echo "google_play: $google_play"
echo "html_path: $html_path"
echo "ignore_sha_check: $ignore_sha_check"
echo "include_tags: $include_tags"
echo "ios_device: $ios_device"
echo "ios_version: $ios_version"
echo "json: $json"
echo "json_file: $json_file"
echo "json_file_name: $json_file_name"
echo "junit_path: $junit_path"
echo "maestro_chrome_onboarding: $maestro_chrome_onboarding"
echo "maestro_version: $maestro_version"
echo "metadata: $metadata"
echo "name: $name"
echo "orientation: $orientation"
echo "report: $report"
echo "retry: $retry"
echo "runner_type: $runner_type"
echo "show_crosshairs: $show_crosshairs"
echo "workspace: $workspace"
echo "app_url: $app_url"
echo "disable_animations: $disable_animations"
echo "quiet: $quiet"
echo "use_beta: $use_beta"
echo "Running command: npx --yes \"$DCD_VERSION\" cloud --quiet \
--apiKey \"$api_key\" \
${allure_path:+--allure-path \"$allure_path\"} \
${is_android_no_snapshot:+--android-no-snapshot} \
${android_api_level:+--android-api-level \"$android_api_level\"} \
${android_device:+--android-device \"$android_device\"} \
${api_url:+--api-url \"$api_url\"} \
${app_binary_id:+--app-binary-id \"$app_binary_id\"} \
${artifacts_path:+--artifacts-path \"$artifacts_path\"} \
${is_async:+--async} \
${config:+--config \"$config\"} \
${is_debug:+--debug} \
${device_locale:+--device-locale \"$device_locale\"} \
${download_artifacts:+--download-artifacts \"$download_artifacts\"} \
${is_dry_run:+--dry-run} \
${exclude_flows:+--exclude-flows \"$exclude_flows\"} \
${exclude_tags:+--exclude-tags \"$exclude_tags\"} \
${is_google_play:+--google-play} \
${html_path:+--html-path \"$html_path\"} \
${is_ignore_sha_check:+--ignore-sha-check} \
${include_tags:+--include-tags \"$include_tags\"} \
${ios_device:+--ios-device \"$ios_device\"} \
${ios_version:+--ios-version \"$ios_version\"} \
${is_json:+--json} \
${is_json_file:+--json-file} \
${json_file_name:+--json-file-name \"$json_file_name\"} \
${junit_path:+--junit-path \"$junit_path\"} \
${is_maestro_chrome_onboarding:+--maestro-chrome-onboarding} \
${maestro_version:+--maestro-version \"$maestro_version\"} \
${name:+--name \"$name\"} \
${orientation:+--orientation \"$orientation\"} \
${report:+--report \"$report\"} \
${retry:+--retry \"$retry\"} \
${runner_type:+--runner-type \"$runner_type\"} \
${is_show_crosshairs:+--show-crosshairs} \
${app_url:+--app-url \"$app_url\"} \
${is_disable_animations:+--disable-animations} \
${is_quiet:+--quiet} \
${env_list_parsed} \
${metadata_parsed} \
\"$app_file\" \"$workspace\""
# Capture the command output and display it
echo "Waiting for full test results so we can parse outputs... this may take a while for non-async tests"
echo "Check status at https://console.devicecloud.dev/results"
OUTPUT=$(npx --yes "$DCD_VERSION" cloud --quiet \
--apiKey "$api_key" \
${allure_path:+--allure-path "$allure_path"} \
${is_android_no_snapshot:+--android-no-snapshot} \
${android_api_level:+--android-api-level "$android_api_level"} \
${android_device:+--android-device "$android_device"} \
${api_url:+--api-url "$api_url"} \
${app_binary_id:+--app-binary-id "$app_binary_id"} \
${artifacts_path:+--artifacts-path "$artifacts_path"} \
${is_async:+--async} \
${config:+--config "$config"} \
${is_debug:+--debug} \
${device_locale:+--device-locale "$device_locale"} \
${download_artifacts:+--download-artifacts "$download_artifacts"} \
${is_dry_run:+--dry-run} \
${exclude_flows:+--exclude-flows "$exclude_flows"} \
${exclude_tags:+--exclude-tags "$exclude_tags"} \
${is_google_play:+--google-play} \
${html_path:+--html-path "$html_path"} \
${is_ignore_sha_check:+--ignore-sha-check} \
${include_tags:+--include-tags "$include_tags"} \
${ios_device:+--ios-device "$ios_device"} \
${ios_version:+--ios-version "$ios_version"} \
${is_json:+--json} \
${is_json_file:+--json-file} \
${json_file_name:+--json-file-name "$json_file_name"} \
${junit_path:+--junit-path "$junit_path"} \
${is_maestro_chrome_onboarding:+--maestro-chrome-onboarding} \
${maestro_version:+--maestro-version "$maestro_version"} \
${name:+--name "$name"} \
${orientation:+--orientation "$orientation"} \
${report:+--report "$report"} \
${retry:+--retry "$retry"} \
${runner_type:+--runner-type "$runner_type"} \
${is_show_crosshairs:+--show-crosshairs} \
${app_url:+--app-url "$app_url"} \
${is_disable_animations:+--disable-animations} \
${is_quiet:+--quiet} \
${env_list_parsed} \
${metadata_parsed} \
"$app_file" "$workspace" 2>&1) || EXIT_CODE=$?
echo "$OUTPUT"
# Extract upload ID from console URL
UPLOAD_ID=$(echo "$OUTPUT" | grep -o 'upload=[a-zA-Z0-9-]*' | cut -d= -f2 | head -n1)
if [ -n "$UPLOAD_ID" ]; then
# Get test status using the status command
STATUS_OUTPUT=$(npx --yes "$DCD_VERSION" status --json --upload-id "$UPLOAD_ID" --api-key "$api_key" ${api_url:+--api-url "$api_url"})
# Extract values from status JSON using grep and sed
# Console URL
CONSOLE_URL=$(echo "$OUTPUT" | grep -o 'https://console\.devicecloud\.dev/results?upload=[a-zA-Z0-9-]*')
envman add --key DEVICE_CLOUD_CONSOLE_URL --value "$CONSOLE_URL"
# Status
TEST_STATUS=$(echo "$STATUS_OUTPUT" | grep -o '"status":"[^"]*"' | cut -d'"' -f4)
envman add --key DEVICE_CLOUD_UPLOAD_STATUS --value "$TEST_STATUS"
# Flow Results
FLOW_RESULTS=$(echo "$STATUS_OUTPUT" | grep -o '"tests":\[[^]]*\]')
envman add --key DEVICE_CLOUD_FLOW_RESULTS --value "$FLOW_RESULTS"
# App Binary ID
APP_BINARY_ID=$(echo "$STATUS_OUTPUT" | grep -o '"appBinaryId":"[^"]*"' | cut -d'"' -f4)
if [ -n "$APP_BINARY_ID" ]; then
envman add --key DEVICE_CLOUD_APP_BINARY_ID --value "$APP_BINARY_ID"
fi
# Set exit code based on status
if [ "$TEST_STATUS" = "FAILED" ]; then
EXIT_CODE=1
elif [ "$TEST_STATUS" = "PASSED" ]; then
EXIT_CODE=0
fi
fi
# Handle artifacts download
if [ -n "$download_artifacts" ] && [ -f "artifacts.zip" ]; then
case "$download_artifacts" in
"ALL"|"FAILED")
echo "Extracting artifacts.zip (mode: $download_artifacts)..."
unzip -o artifacts.zip -d "$BITRISE_DEPLOY_DIR"
if [ $? -eq 0 ]; then
echo "Artifacts successfully extracted to $BITRISE_DEPLOY_DIR"
else
echo "Warning: Failed to extract artifacts.zip"
EXIT_CODE=1
fi
;;
*)
echo "Warning: Invalid download_artifacts value: $download_artifacts. Expected 'ALL' or 'FAILED'"
;;
esac
fi
exit $EXIT_CODE