ci: Prevent some more CI failures

Many times the CI pipeline fails in the early stages because the APT
repo for LLVM is being updated.
Add a retry mechanism for some more APT commands.
This commit is contained in:
LemonBoy
2020-12-04 13:04:10 +01:00
parent 58241364cb
commit 77031baf98

View File

@@ -3,32 +3,38 @@
set -x
set -e
# This parameters we wait at most 2mins, it should be enough to sort out any
# transient error.
CMD_MAX_RETRY=12
CMD_WAIT_TIME=10s
# Execute the given command and, in case of failure, try to execute it again
# after sleeping for CMD_WAIT_TIME.
# We give up after retrying CMD_MAX_RETRY times.
retry() {
for i in $(seq 1 "$CMD_MAX_RETRY"); do
"$@" && return
echo "command \"$@\" failed, retrying..."
sleep ${CMD_WAIT_TIME}
done
echo "command \"$@\" failed, giving up..."
exit 1
}
BUILDDIR="$(pwd)"
sudo sh -c 'echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main" >> /etc/apt/sources.list'
wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
retry 'wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -'
retry sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get remove -y llvm-*
sudo rm -rf /usr/local/*
# Some APT mirrors can be flaky, retry the download instead of failing right
# away.
APT_MAX_RETRY=3
for i in $(seq 1 "$APT_MAX_RETRY"); do
sudo apt-get update -q
sudo apt-get install -y \
retry sudo apt-get update -q
retry sudo apt-get install -y \
libxml2-dev libclang-11-dev llvm-11 llvm-11-dev liblld-11-dev cmake s3cmd \
gcc-7 g++-7 ninja-build tidy \
&& break
if [ "$i" -eq "$APT_MAX_RETRY" ]; then
echo 'apt-get failed, giving up...'
exit 1
fi
echo 'apt-get failed, retrying...'
sleep 5s
done
QEMUBASE="qemu-linux-x86_64-5.1.0"
wget https://ziglang.org/deps/$QEMUBASE.tar.xz