diff --git a/.github/actions/install-with-retries/install-with-retries.sh b/.github/actions/install-with-retries/install-with-retries.sh index c9b1d0f8a01..945b335fc58 100755 --- a/.github/actions/install-with-retries/install-with-retries.sh +++ b/.github/actions/install-with-retries/install-with-retries.sh @@ -17,9 +17,9 @@ if [ "$SKIP_CYPRESS_BINARY" = "true" ]; then export CYPRESS_INSTALL_BINARY=0 fi -for i in {1..3}; do +for i in {1..4}; do echo "====================" - echo "Attempt $i out of 3:" + echo "Attempt $i out of 4:" echo "====================" if [ "$NO_LOCKFILE" = "true" ]; then @@ -32,10 +32,14 @@ for i in {1..3}; do # Check return value and exit early if successful return_value=$? [ $return_value -eq 0 ] && break - echo "[ERROR]: yarn install failed with exit code $return_value, waiting to retry..." - # Sleep 5 seconds before retrying - sleep 5 + # Don't add delay at end of last attempt if last attempt fails + if [ "$i" -le 3 ]; then + # NPM publish can be flaky causing failed installs + # Add exponential backoff between retries: [4/16/64]s ~= [5/15/60]s + echo "[ERROR]: yarn install failed with exit code $return_value, waiting to retry in $((4 * i)) seconds..." + sleep $((4 ** i)) + fi done # exit 0 if last `yarn install` was successful, non-zero otherwise diff --git a/build-system-tests/scripts/install-dependencies-with-retries.sh b/build-system-tests/scripts/install-dependencies-with-retries.sh index c80ca718c41..e2a14f30974 100644 --- a/build-system-tests/scripts/install-dependencies-with-retries.sh +++ b/build-system-tests/scripts/install-dependencies-with-retries.sh @@ -4,7 +4,7 @@ # Takes 2 parameters: the package manager and the dependencies to be installed # Usage: install_with_retries npm "$DEPENDENCIES" or install_with_retries yarn "$DEPENDENCIES" install_dependencies_with_retries() { - local retries=3 + local retries=4 local attempt=1 echo "Disable exit-on-error temporarily" echo "set +e" @@ -20,10 +20,13 @@ install_dependencies_with_retries() { set -e break fi + # Add exponential backoff delay between failed attempts + # [4/16/64]s ~= [5/15/60]s + local wait=$((4 ** attempt)) attempt=$((attempt + 1)) if [ $attempt -le $retries ]; then - echo "$1 install failed. Retrying in 5 seconds..." - sleep 5 + echo "$1 install failed. Retrying in $wait seconds..." + sleep $wait else echo "$1 install failed after $retries attempts." echo "Re-enable exit-on-error" diff --git a/build-system-tests/scripts/mega-app-install.sh b/build-system-tests/scripts/mega-app-install.sh index 34e57f5a306..49d4c0318a5 100755 --- a/build-system-tests/scripts/mega-app-install.sh +++ b/build-system-tests/scripts/mega-app-install.sh @@ -108,7 +108,7 @@ else # react-native-safe-area-context v5.0.0+ does not support RN 0.74 and lower DEPENDENCIES="$TAGGED_UI_FRAMEWORK @aws-amplify/react-native aws-amplify react-native-safe-area-context@^4.2.5 @react-native-community/netinfo @react-native-async-storage/async-storage react-native-get-random-values react-native-url-polyfill" echo "npm install $DEPENDENCIES" - npm install $DEPENDENCIES + install_dependencies_with_retries npm "$DEPENDENCIES" if [[ "$BUILD_TOOL" == "expo" ]]; then if [[ "$FRAMEWORK_VERSION" == "0.75" ]]; then # Expo SDK version 51.0.0 supports RN 0.74 and 0.75 but installs 0.74 by default https://expo.dev/changelog/2024/08-14-react-native-0.75#2-install-updated-packages