mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-15 06:19:21 +00:00
[Ubuntu] Added HTTP status code check to download_with_retries (#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>
This commit is contained in:
@@ -14,22 +14,29 @@ download_with_retries() {
|
|||||||
local COMPRESSED="$4"
|
local COMPRESSED="$4"
|
||||||
|
|
||||||
if [[ $COMPRESSED == "compressed" ]]; then
|
if [[ $COMPRESSED == "compressed" ]]; then
|
||||||
COMMAND="curl $URL -4 -sL --compressed -o '$DEST/$NAME'"
|
local COMMAND="curl $URL -4 -sL --compressed -o '$DEST/$NAME' -w '%{http_code}'"
|
||||||
else
|
else
|
||||||
COMMAND="curl $URL -4 -sL -o '$DEST/$NAME'"
|
local COMMAND="curl $URL -4 -sL -o '$DEST/$NAME' -w '%{http_code}'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Downloading '$URL' to '${DEST}/${NAME}'..."
|
echo "Downloading '$URL' to '${DEST}/${NAME}'..."
|
||||||
i=20
|
retries=20
|
||||||
while [ $i -gt 0 ]; do
|
interval=30
|
||||||
((i--))
|
while [ $retries -gt 0 ]; do
|
||||||
eval $COMMAND
|
((retries--))
|
||||||
if [ $? != 0 ]; then
|
# Temporary disable exit on error to retry on non-zero exit code
|
||||||
sleep 30
|
set +e
|
||||||
else
|
http_code=$(eval $COMMAND)
|
||||||
|
exit_code=$?
|
||||||
|
if [ $http_code -eq 200 ] && [ $exit_code -eq 0 ]; then
|
||||||
echo "Download completed"
|
echo "Download completed"
|
||||||
return 0
|
return 0
|
||||||
|
else
|
||||||
|
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"
|
||||||
|
sleep 30
|
||||||
fi
|
fi
|
||||||
|
# Enable exit on error back
|
||||||
|
set -e
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Could not download $URL"
|
echo "Could not download $URL"
|
||||||
@@ -58,4 +65,4 @@ get_toolset_value() {
|
|||||||
local toolset_path=$(get_toolset_path)
|
local toolset_path=$(get_toolset_path)
|
||||||
local query=$1
|
local query=$1
|
||||||
echo "$(jq -r "$query" $toolset_path)"
|
echo "$(jq -r "$query" $toolset_path)"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ source $HELPER_SCRIPTS/etc-environment.sh
|
|||||||
GRAALVM_ROOT=/usr/local/graalvm
|
GRAALVM_ROOT=/usr/local/graalvm
|
||||||
export GRAALVM_11_ROOT=$GRAALVM_ROOT/graalvm-ce-java11*
|
export GRAALVM_11_ROOT=$GRAALVM_ROOT/graalvm-ce-java11*
|
||||||
|
|
||||||
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"))')
|
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"))')
|
||||||
download_with_retries "$url" "/tmp" "graalvm-archive.tar.gz"
|
download_with_retries "$url" "/tmp" "graalvm-archive.tar.gz"
|
||||||
mkdir $GRAALVM_ROOT
|
mkdir $GRAALVM_ROOT
|
||||||
tar -xzf "/tmp/graalvm-archive.tar.gz" -C $GRAALVM_ROOT
|
tar -xzf "/tmp/graalvm-archive.tar.gz" -C $GRAALVM_ROOT
|
||||||
@@ -18,4 +18,4 @@ setEtcEnvironmentVariable "GRAALVM_11_ROOT" $GRAALVM_11_ROOT
|
|||||||
# Install Native Image
|
# Install Native Image
|
||||||
$GRAALVM_11_ROOT/bin/gu install native-image
|
$GRAALVM_11_ROOT/bin/gu install native-image
|
||||||
|
|
||||||
invoke_tests "Tools" "GraalVM"
|
invoke_tests "Tools" "GraalVM"
|
||||||
|
|||||||
Reference in New Issue
Block a user