Skip to content

Commit 6637167

Browse files
[Ubuntu] Added HTTP status code check to download_with_retries (actions#3721)
* Disable exit on error temporary to implement retry logic based on exit code * Check HTTP response code and retry if it's not 200 * Make variables local to not interfere with other scripts Co-authored-by: Mikhail Timofeev <48208649+miketimofeev@users.noreply.github.com>
1 parent 6576bc7 commit 6637167

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

images/linux/scripts/helpers/install.sh

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,29 @@ download_with_retries() {
1414
local COMPRESSED="$4"
1515

1616
if [[ $COMPRESSED == "compressed" ]]; then
17-
COMMAND="curl $URL -4 -sL --compressed -o '$DEST/$NAME'"
17+
local COMMAND="curl $URL -4 -sL --compressed -o '$DEST/$NAME' -w '%{http_code}'"
1818
else
19-
COMMAND="curl $URL -4 -sL -o '$DEST/$NAME'"
19+
local COMMAND="curl $URL -4 -sL -o '$DEST/$NAME' -w '%{http_code}'"
2020
fi
2121

2222
echo "Downloading '$URL' to '${DEST}/${NAME}'..."
23-
i=20
24-
while [ $i -gt 0 ]; do
25-
((i--))
26-
eval $COMMAND
27-
if [ $? != 0 ]; then
28-
sleep 30
29-
else
23+
retries=20
24+
interval=30
25+
while [ $retries -gt 0 ]; do
26+
((retries--))
27+
# Temporary disable exit on error to retry on non-zero exit code
28+
set +e
29+
http_code=$(eval $COMMAND)
30+
exit_code=$?
31+
if [ $http_code -eq 200 ] && [ $exit_code -eq 0 ]; then
3032
echo "Download completed"
3133
return 0
34+
else
35+
echo "Error — Either HTTP response code for '$URL' is wrong - '$http_code' or exit code is not 0 - '$exit_code'. Waiting $interval seconds before the next attempt, $retries attempts left"
36+
sleep 30
3237
fi
38+
# Enable exit on error back
39+
set -e
3340
done
3441

3542
echo "Could not download $URL"
@@ -58,4 +65,4 @@ get_toolset_value() {
5865
local toolset_path=$(get_toolset_path)
5966
local query=$1
6067
echo "$(jq -r "$query" $toolset_path)"
61-
}
68+
}

images/linux/scripts/installers/graalvm.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ source $HELPER_SCRIPTS/etc-environment.sh
77
GRAALVM_ROOT=/usr/local/graalvm
88
export GRAALVM_11_ROOT=$GRAALVM_ROOT/graalvm-ce-java11*
99

10-
url=$(curl -s https://api.github.com/repos/graalvm/graalvm-ce-builds/releases/latest | jq -r '.assets[].browser_download_url | select(contains("graalvm-ce-java11-linux-amd64"))')
10+
url=$(curl -s https://api.github.com/repos/graalvm/graalvm-ce-builds/releases/latest | jq -r '.assets[].browser_download_url | select(contains("graalvm-ce-java11-linux-amd64") and endswith("tar.gz"))')
1111
download_with_retries "$url" "/tmp" "graalvm-archive.tar.gz"
1212
mkdir $GRAALVM_ROOT
1313
tar -xzf "/tmp/graalvm-archive.tar.gz" -C $GRAALVM_ROOT
@@ -18,4 +18,4 @@ setEtcEnvironmentVariable "GRAALVM_11_ROOT" $GRAALVM_11_ROOT
1818
# Install Native Image
1919
$GRAALVM_11_ROOT/bin/gu install native-image
2020

21-
invoke_tests "Tools" "GraalVM"
21+
invoke_tests "Tools" "GraalVM"

0 commit comments

Comments
 (0)