Files
react-native/scripts/retry3
T
Tim Yung 833661452d RN: Make retry3 Portable in CI Scripts
Summary:
Moves the `retry3` utility function into its own file so that it can be reused in other steps that are not related to Android.

Changelog:
[Internal]

Reviewed By: rickhanlonii, cipolleschi

Differential Revision: D39889996

fbshipit-source-id: bf79cc19ad6178af0a0d8117a81116e0c32f4333
2022-09-28 10:57:07 -07:00

25 lines
448 B
Bash
Executable File

#!/usr/bin/env bash
function retry3 {
local n=1
local max=3
local delay=1
while true; do
# shellcheck disable=SC2015
"$@" && break || {
if [[ $n -lt $max ]]; then
((n++))
echo "Command failed. Attempt $n/$max:"
sleep $delay;
else
echo "The command has failed after $n attempts." >&2
return 1
fi
}
done
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
retry3 "$@"
fi