github actions: retry up to 3 times when connection has been dropped

This commit is contained in:
Leonid Pliushch 2021-10-07 14:49:01 +03:00
parent c8a0cfc528
commit 150479d560
No known key found for this signature in database
GPG Key ID: 45F2964132545795
1 changed files with 51 additions and 25 deletions

View File

@ -216,16 +216,27 @@ jobs:
if [ "$uploaded_files" = "true" ]; then if [ "$uploaded_files" = "true" ]; then
echo "[*] Adding packages to repository '$REPOSITORY_NAME'..." echo "[*] Adding packages to repository '$REPOSITORY_NAME'..."
curl_response=$( # Retry up to 3 times.
curl \ http_status_code=""
--silent \ for _ in {1..3}; do
--user "${{ secrets.APTLY_API_AUTH }}" \ curl_response=$(
--request POST \ set +e
--write-out "|%{http_code}" \ curl \
https://packages.termux.org/aptly-api/repos/${REPOSITORY_NAME}/file/${REPOSITORY_NAME}-${{ github.sha }} || true --silent \
) --user "${{ secrets.APTLY_API_AUTH }}" \
--request POST \
--write-out "|%{http_code}" \
https://packages.termux.org/aptly-api/repos/${REPOSITORY_NAME}/file/${REPOSITORY_NAME}-${{ github.sha }}
)
http_status_code=$(echo "$curl_response" | cut -d'|' -f2)
http_status_code=$(echo "$curl_response" | cut -d'|' -f2) if [ "$http_status_code" = "000" ]; then
echo "[*] Server/proxy has dropped connection, retrying (adding packages)..."
continue
else
break
fi
done
if [ "$http_status_code" = "200" ]; then if [ "$http_status_code" = "200" ]; then
warnings=$(echo "$curl_response" | cut -d'|' -f1 | jq '.Report.Warnings' | jq -r '.[]') warnings=$(echo "$curl_response" | cut -d'|' -f1 | jq '.Report.Warnings' | jq -r '.[]')
@ -235,30 +246,45 @@ jobs:
echo "$warnings" echo "$warnings"
echo echo
fi fi
else
echo "[!] Got http_status_code == '$http_status_code', package may not appear in repository."
fi fi
# Usually temporary directory is deleted automatically, but in certain cases it is left. # Usually temporary directory is deleted automatically, but in certain cases it is left.
aptly_delete_dir aptly_delete_dir
# Final part to make changes appear in web root. # Final part to make changes appear in web root.
echo "[*] Publishing repository changes..." echo "[*] Publishing repository changes..."
set +e # Retry up to 3 times.
curl \ http_status_code=""
--silent \ for _ in {1..3}; do
--user "${{ secrets.APTLY_API_AUTH }}" \ curl_response=$(
--header 'Content-Type: application/json' \ set +e
--request PUT \ curl \
--data '{"Signing": {"Passphrase": "${{ secrets.GPG_PASSPHRASE }}"}}' \ --silent \
https://packages.termux.org/aptly-api/publish/${REPOSITORY_NAME}/${REPOSITORY_DISTRIBUTION} --user "${{ secrets.APTLY_API_AUTH }}" \
exit_code=$? --header 'Content-Type: application/json' \
echo --request PUT \
--data '{"Signing": {"Passphrase": "${{ secrets.GPG_PASSPHRASE }}"}}' \
https://packages.termux.org/aptly-api/publish/${REPOSITORY_NAME}/${REPOSITORY_DISTRIBUTION}
)
http_status_code=$(echo "$curl_response" | cut -d'|' -f2)
if [ "$exit_code" = 0 ]; then if [ "$http_status_code" = "000" ]; then
echo "[*] Server/proxy has dropped connection, retrying (publishing changes)..."
continue
else
break
fi
done
if [ "$http_status_code" = "200" ]; then
echo "[*] Repository updated successfully." echo "[*] Repository updated successfully."
elif [ "$exit_code" = 52 ]; then elif [ "$http_status_code" = "000" ]; then
echo "[!] Repository update takes more time than expected, server returned empty response." echo "[!] Server/proxy has dropped connection."
echo "[!] This is expected if large amount of data has been submitted." exit 1
else else
echo "[!] curl exited with error code ${exit_code}." echo "[!] Got http_status_code == '$http_status_code'"
exit "$exit_code" exit 1
fi fi
fi fi