]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/dist-various-2/shared.sh
fb917b0510e40261f28ac8ad3e7efa5a71694700
[rust.git] / src / ci / docker / dist-various-2 / shared.sh
1 hide_output() {
2   set +x
3   on_err="
4 echo ERROR: An error was encountered with the build.
5 cat /tmp/build.log
6 exit 1
7 "
8   trap "$on_err" ERR
9   bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
10   PING_LOOP_PID=$!
11   "$@" &> /tmp/build.log
12   trap - ERR
13   kill $PING_LOOP_PID
14   set -x
15 }
16
17 function retry {
18   echo "Attempting with retry:" "$@"
19   local n=1
20   local max=5
21   while true; do
22     "$@" && break || {
23       if [[ $n -lt $max ]]; then
24         sleep $n  # don't retry immediately
25         ((n++))
26         echo "Command failed. Attempt $n/$max:"
27       else
28         echo "The command has failed after $n attempts."
29         return 1
30       fi
31     }
32   done
33 }