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
This commit is contained in:
Tim Yung 2022-09-28 10:57:07 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 7f061f8651
Коммит 833661452d
4 изменённых файлов: 26 добавлений и 20 удалений

Просмотреть файл

@ -33,7 +33,7 @@ node cli.js bundle --platform android --dev true --entry-file ReactAndroid/src/a
# build test APK # build test APK
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source ./scripts/android-setup.sh && NO_BUCKD=1 retry3 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=1 source ./scripts/android-setup.sh && NO_BUCKD=1 scripts/retry3 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=1
# run installed apk with tests # run installed apk with tests
node ./.circleci/Dockerfiles/scripts/run-android-ci-instrumentation-tests.js "$*" node ./.circleci/Dockerfiles/scripts/run-android-ci-instrumentation-tests.js "$*"

Просмотреть файл

@ -617,7 +617,7 @@ jobs:
if [[ ! -e ReactAndroid/src/androidTest/assets/AndroidTestBundle.js ]]; then if [[ ! -e ReactAndroid/src/androidTest/assets/AndroidTestBundle.js ]]; then
echo "JavaScript bundle missing, cannot run instrumentation tests. Verify Build JavaScript Bundle step completed successfully."; exit 1; echo "JavaScript bundle missing, cannot run instrumentation tests. Verify Build JavaScript Bundle step completed successfully."; exit 1;
fi fi
source scripts/android-setup.sh && NO_BUCKD=1 retry3 timeout 300 buck build ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=$BUILD_THREADS source scripts/android-setup.sh && NO_BUCKD=1 scripts/retry3 timeout 300 buck build ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=$BUILD_THREADS
- run: - run:
name: Collect Test Results name: Collect Test Results

Просмотреть файл

@ -94,21 +94,3 @@ function waitForAVD {
echo "Skipping AVD-related test setup..." echo "Skipping AVD-related test setup..."
fi fi
} }
function retry3 {
local n=1
local max=3
local delay=1
while true; do
"$@" && 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
}

24
scripts/retry3 Executable file
Просмотреть файл

@ -0,0 +1,24 @@
#!/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