Skip to content

Commit c0dbade

Browse files
committed
uploadToCentral.sh: capture the HTTP status and retry if it's 400
1 parent 025f706 commit c0dbade

1 file changed

Lines changed: 37 additions & 4 deletions

File tree

bash/uploadToCentral.sh

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,41 @@ token=$(printf %s:%s "${centralUsername}" "${centralPassword}" | base64)
2828

2929
# Send a POST request to upload the repository:
3030

31-
curl --include --request POST \
32-
'https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/com.github.stephengold' \
31+
server='ossrh-staging-api.central.sonatype.com'
32+
endpoint='/manual/upload/defaultRepository/com.github.stephengold'
33+
url="https://${server}${endpoint}"
34+
35+
statusCode=$(curl "${url}" \
36+
--no-progress-meter \
37+
--output postData1.txt \
38+
--write-out '%{response_code}' \
39+
--request POST \
3340
--header 'accept: */*' \
34-
--header "Authorization: Bearer $token" \
35-
--data ''
41+
--header "Authorization: Bearer ${token}" \
42+
--data '')
43+
44+
echo "Status code = ${statusCode}"
45+
echo 'Received data:'
46+
cat postData1.txt
47+
echo '[EOF]'
48+
49+
# Retry if the default repository isn't found (status=400).
50+
51+
if [ "${statusCode}" == "400" ]; then
52+
echo "Will retry after 30 seconds."
53+
sleep 30
54+
55+
statusCode2=$(curl "${url}" \
56+
--no-progress-meter \
57+
--output postData2.txt \
58+
--write-out '%{response_code}' \
59+
--request POST \
60+
--header 'accept: */*' \
61+
--header "Authorization: Bearer ${token}" \
62+
--data '')
63+
64+
echo "Status code = ${statusCode2}"
65+
echo 'Received data:'
66+
cat postData2.txt
67+
echo '[EOF]'
68+
fi

0 commit comments

Comments
 (0)