-
Notifications
You must be signed in to change notification settings - Fork 7
/
step.sh
73 lines (58 loc) · 1.56 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
#!/bin/bash
readonly STEP_VERSION=1.1.3 # id=step-version : Do not modify this line manually.
readonly output_file="output.json"
info() {
echo "[INFO] $@"
}
err() {
echo "[ERROR] $@" 1>&2
}
fatal() {
err "$@"
exit 1
}
upload_app() {
local -r all_fields=(
"message=$message"
"distribution_key=$distribution_key"
"distribution_name=$distribution_name"
"release_note=$release_note"
"disable_notify=$disable_notify"
)
local field= fields=()
for field in "${all_fields[@]}"; do
if [[ "$field" =~ ^.*=$ ]]; then
# skip
continue
else
fields+=("--form-string")
fields+=("$field")
fi
done
curl -L# -X POST \
-o "$output_file" \
-H "Authorization: token $api_key" \
-H "Accept: application/json" \
-A "DeployGateUploadAppBitriseStep/$STEP_VERSION" \
-F "file=@$app_path" \
"${fields[@]}" \
"https://deploygate.com/api/users/$owner_name/apps"
}
parse_error_field() {
cat - | ruby -rjson -ne 'puts JSON.parse($_)["error"]'
}
if [[ ! -f "$app_path" ]]; then
fatal "$app_path is not found. Please make sure the application file has been successfuly created in the previous steps."
fi
# this will create the `output.json``
if ! upload_app; then
fatal "your upload request failed and didn't reach to the server due to misconfiguration."
fi
envman add --key DEPLOYGATE_UPLOAD_APP_STEP_RESULT_JSON --valuefile "$output_file"
cat "$output_file"
echo
if [[ "$(cat output.json | parse_error_field)" == "false" ]]; then
info "Uploaded successfully."
else
fatal "Upload failed."
fi