diff options
Diffstat (limited to 'ci/run_retry.sh')
-rwxr-xr-x | ci/run_retry.sh | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/ci/run_retry.sh b/ci/run_retry.sh new file mode 100755 index 00000000..9105c9cc --- /dev/null +++ b/ci/run_retry.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# vim: set sts=4 sw=4 et : + +set -o pipefail + +ERRORS=( + "Warning: An error occurred while preparing SDK package Android SDK Tools: Connection reset." + "The Xcode build system has crashed. Build again to continue." +) +RETRIES=3 +LOGFILE="/tmp/logfile.txt" + +while true; do + spurious_error= + "$@" | tee "$LOGFILE" 2>&1 + ret=$? + [[ $ret == 0 ]] && break + while read line; do + for error in "${ERRORS[@]}"; do + if [[ $line =~ $error ]]; then + spurious_error=$line + break 2 + fi + done + done < "$LOGFILE" + rm -f "$LOGFILE" + if [[ $spurious_error == '' ]] || [[ $RETRIES == 0 ]]; then + exit $ret + fi + RETRIES=$((RETRIES-1)) + echo "Retrying, caught spurious failure: $spurious_error" +done |