-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstep.sh
296 lines (232 loc) · 9.1 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
#!/usr/bin/env bash
# fail if any commands fail
set -e
# debug log
if [ "${show_debug_logs}" == "yes" ]; then
set -x
fi
function getToken() {
printf "\n\nObtaining a Token...\n"
response=$(curl --silent -X POST \
https://connect-api.cloud.huawei.com/api/oauth2/v1/token \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"grant_type": "client_credentials",
"client_id": "'${huawei_client_id}'",
"client_secret": "'${huawei_client_secret}'"
}' || true)
if [[ -z "$response" ]]; then
printf "\n ❌ An error occurred while obtaining a token from AppGallery Connect. Check your network connection and your credentials 😢\n"
exit 1
fi
echo "$response" >token.json
CODE=$(jq -r '.ret.code' token.json)
if [ "${CODE}" != "null" ] && [ "${CODE}" != "0" ]; then
printf "\n ❌ An error occurred while obtaining a token from AppGallery Connect 😢\n. Please check the response for further details.\n"
echo "$response"
exit 1
fi
printf "Obtaining a Token ✅\n"
}
function getFileUploadUrl() {
ACCESS_TOKEN=$(jq -r '.access_token' token.json)
FILE_EXT="${file_path##*.}"
RELEASE_TYPE=$(getReleaseTypeValue)
printf "\nObtaining the File Upload URL...\n"
response=$(curl --silent -X GET \
'https://connect-api.cloud.huawei.com/api/publish/v2/upload-url?appId='"${huawei_app_id}"'&suffix='"${FILE_EXT}"'&releaseType='"${RELEASE_TYPE}" \
-H 'Authorization: Bearer '"${ACCESS_TOKEN}"'' \
-H 'client_id: '"${huawei_client_id}"'' || true)
if [[ -z "$response" ]]; then
printf "\n ❌ An error occurred while obtaining the file upload URL. Check your network connection and the parameters used 😢\n"
exit 1
fi
echo "$response" >uploadurl.json
CODE=$(jq -r '.ret.code' uploadurl.json)
if [ "${CODE}" != "null" ] && [ "${CODE}" != "0" ]; then
printf "\n ❌ An error occurred while obtaining the file upload URL. 😢\n"
echo "$response"
exit 1
fi
printf "Obtaining the File Upload URL ✅\n"
}
function getReleaseTypeValue() {
if [ "${release_type}" == "By Phase" ]; then
releaseTypeValue=3
else
releaseTypeValue=1
fi
echo $releaseTypeValue
}
function uploadFile() {
UPLOAD_URL=$(jq -r '.uploadUrl' uploadurl.json)
UPLOAD_AUTH_CODE=$(jq -r '.authCode' uploadurl.json)
printf "\nUploading a File...\n"
if [ ! -f "$file_path" ]; then
printf "\n ❌ File '$file_path' does not exist 😢\n"
exit 1
fi
response=$(curl --silent -X POST \
"${UPLOAD_URL}" \
-H 'Accept: application/json' \
-F authCode="${UPLOAD_AUTH_CODE}" \
-F fileCount=1 \
-F parseType=1 \
-F file="@${file_path}" || true)
if [[ -z "$response" ]]; then
printf "\n ❌ An error occurred while uploading the file. Check your network connection and file path 😢\n"
exit 1
fi
echo "$response" >uploadfile.json
CODE=$(jq -r '.result.UploadFileRsp.ifSuccess' uploadfile.json)
if [ "${CODE}" != "1" ]; then
printf "\n ❌ An error occurred while uploading the file.. 😢\n"
echo "$response"
exit 1
fi
printf "Uploading a File ✅\n"
}
function updateAppFileInfo() {
ACCESS_TOKEN=$(jq -r '.access_token' token.json)
FILE_DEST_URL=$(jq -r '.result.UploadFileRsp.fileInfoList[0].fileDestUlr' uploadfile.json)
FILE_SIZE=$(jq -r '.result.UploadFileRsp.fileInfoList[0].size' uploadfile.json)
printf "\nUpdating the App File Information with the previous uploaded file: '${huawei_filename}'\n"
response=$(curl --silent -X PUT \
'https://connect-api.cloud.huawei.com/api/publish/v2/app-file-info?appId='"$huawei_app_id"'' \
-H 'Authorization: Bearer '"${ACCESS_TOKEN}"'' \
-H 'Content-Type: application/json' \
-H 'client_id: '"${huawei_client_id}"'' \
-H 'releaseType: '"${releaseType}"'' \
-d '{
"fileType":"5",
"files":[
{
"fileName":"'"$huawei_filename"'",
"fileDestUrl":"'"${FILE_DEST_URL}"'",
"size":"'"${FILE_SIZE}"'"
}]
}' || true)
if [[ -z "$response" ]]; then
printf "\n ❌ An error occurred while updating the app file information. Check your network connection and the parameters used😢\n"
exit 1
fi
echo "$response" >result.json
CODE=$(jq -r '.ret.code' result.json)
if [ "${CODE}" != "0" ]; then
printf "\n ❌ An error occurred while updating the app file information 😢\n"
echo "$response"
exit 1
fi
printf "Updating the App File Information with the previous uploaded file ✅\n"
}
function submitApp() {
ACCESS_TOKEN=$(jq -r '.access_token' token.json)
if [ "${release_type}" == "By Phase" ]; then
submitAppPhaseMode
else
submitAppDirectly
fi
}
function submitAppPhaseMode() {
ACCESS_TOKEN=$(jq -r '.access_token' token.json)
RELEASE_TYPE=$(getReleaseTypeValue)
JSON_STRING="{\"phasedReleaseStartTime\":\"$phase_release_start_time+0000\",\"phasedReleaseEndTime\":\"$phase_release_end_time+0000\",\"phasedReleaseDescription\":\"$phase_release_description\",\"phasedReleasePercent\":\"$phase_release_percentage\"}"
printf "\nSubmitting the app in phased release mode...\n"
response=$(curl --silent -X POST \
'https://connect-api.cloud.huawei.com/api/publish/v2/app-submit?appid='"$huawei_app_id"'&releaseType='"${RELEASE_TYPE}" \
-H 'Authorization: Bearer '"${ACCESS_TOKEN}"'' \
-H 'Content-Type: application/json' \
-H 'client_id: '"${huawei_client_id}"'' \
-d "${JSON_STRING}" || true)
if [[ -z "$response" ]]; then
printf "\n ❌ An error occurred while submitting the app in phased release mode. Check your network connection and the parameters used 😢\n"
exit 1
fi
echo "$response" >resultSubmission.json
}
function submitAppDirectly() {
ACCESS_TOKEN=$(jq -r '.access_token' token.json)
printf "\nSubmitting the app directly...\n"
response=$(curl --silent -X POST \
'https://connect-api.cloud.huawei.com/api/publish/v2/app-submit?appid='"$huawei_app_id"'' \
-H 'Authorization: Bearer '"${ACCESS_TOKEN}"'' \
-H 'client_id: '"${huawei_client_id}"'' || true)
if [[ -z "$response" ]]; then
printf "\n ❌ An error occurred while directly submitting the app. Check your network connection and the parameters used 😢\n"
exit 1
fi
echo "$response" >resultSubmission.json
}
function getSubmissionStatus() {
ACCESS_TOKEN=$(jq -r '.access_token' token.json)
PKG_VERSION=$(jq -r '.pkgVersion[0]' result.json)
printf "\nGetting the submission status...\n"
response=$(curl --silent -X GET \
'https://connect-api.cloud.huawei.com/api/publish/v2/aab/complile/status?appId='"${huawei_app_id}"'&pkgIds='"${PKG_VERSION}"'' \
-H 'Authorization: Bearer '"${ACCESS_TOKEN}"'' \
-H 'client_id: '"${huawei_client_id}"'' || true)
if [[ -z "$response" ]]; then
printf "\n ❌ An error occurred while getting the submission status. Check your network connection and the parameters used😢\n"
exit 1
fi
echo "$response" >resultSubmissionStatus.json
}
function showResponseOrSubmitCompletelyAgain() {
ACCESS_TOKEN=$(jq -r '.access_token' token.json)
RET_CODE=$(jq -r '.ret.code' resultSubmission.json)
RET_MESSAGE=$(jq -r '.ret.msg' resultSubmission.json)
if [[ "${RET_CODE}" == 204144727 ]]; then
getSubmissionStatus
SUBMISSION_STATUS=$(jq -r '.aabCompileStatus' resultSubmissionStatus.json)
printf "Submission Status ${SUBMISSION_STATUS}"
i=0
while (("${SUBMISSION_STATUS}" == 1 && i < 16)); do
sleep 20
getSubmissionStatus
SUBMISSION_STATUS=$(jq -r '.aabCompileStatus' resultSubmissionStatus.json)
printf "\nThe Build is currently processing, waiting 20 seconds ⏱️ before trying to submit again...\n"
((i += 1))
done
if [ "${SUBMISSION_STATUS}" == 2 ]; then
submitApp
CODE=$(jq -r '.ret.code' resultSubmission.json)
MESSAGE=$(jq -r '.ret.msg' resultSubmission.json)
printf "\nFinal SubmitRetCode - ${CODE}\n"
printf "\nFinal SubmitRetMessage - ${MESSAGE}\n"
else
printf "\n❌ FAILED to submit the App for Review 😢\n"
fi
elif [[ "${RET_CODE}" == 0 ]]; then
printf "\n🤩 App SUCCESSFULLY SUBMITTED for Review 🎉🎊\n"
else
printf "\n ❌ FAILED to submit the App for Review 😢\n"
printf "${RET_MESSAGE}"
fi
}
function getSubmissionStatus() {
ACCESS_TOKEN=$(jq -r '.access_token' token.json)
PKG_VERSION=$(jq -r '.pkgVersion[0]' result.json)
printf "\nGetting submission status...\n"
response=$(curl --silent -X GET \
'https://connect-api.cloud.huawei.com/api/publish/v2/aab/complile/status?appId='"${huawei_app_id}"'&pkgIds='"${PKG_VERSION}"'' \
-H 'Authorization: Bearer '"${ACCESS_TOKEN}"'' \
-H 'client_id: '"${huawei_client_id}"'' || true)
if [[ -z "$response" ]]; then
printf "\n ❌ An error occurred while getting the submission status. Check your network connection and the parameters used 😢\n"
exit 1
fi
echo "$response" >resultSubmissionStatus.json
}
getToken
getFileUploadUrl
uploadFile
updateAppFileInfo
printf "\nSubmitting app as a Draft...⏳\n"
if [ "${submit_for_review}" == "true" ]; then
submitApp
showResponseOrSubmitCompletelyAgain
else
printf "\n🤩 Your app was successfully submitted as a Draft 🎉\n"
fi
exit 0