Skip to content

Commit

Permalink
chore: add delay between install retries, swap RN to use install script
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffanynwyeung committed Jan 9, 2025
1 parent 89fe9fc commit 5acdf75
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
14 changes: 9 additions & 5 deletions .github/actions/install-with-retries/install-with-retries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion build-system-tests/scripts/mega-app-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5acdf75

Please sign in to comment.