diff --git a/.circleci/config.yml b/.circleci/config.yml index 0656a0ddef5820..ee06aaafc18519 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -813,7 +813,7 @@ jobs: steps: - run: name: "Run Tests: iOS Unit and Integration Tests" - command: yarn test-ios + command: node ./scripts/circleci/run_with_retry.js 3 yarn test-ios - run: name: Zip Derived data folder when: always diff --git a/scripts/circleci/run_with_retry.js b/scripts/circleci/run_with_retry.js new file mode 100755 index 00000000000000..a771521167983b --- /dev/null +++ b/scripts/circleci/run_with_retry.js @@ -0,0 +1,40 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +const {spawnSync} = require('child_process'); + +function retryCommand(maxRetries, command) { + for (let i = 1; i <= maxRetries; i++) { + console.log(`Attempt ${i}: ${command}`); + const result = spawnSync(command, {shell: true, stdio: 'inherit'}); + + if (result.status === 0) { + console.log(`Command succeeded on attempt ${i}`); + process.exit(0); + } else { + console.log(`Command failed on attempt ${i}`); + if (i < maxRetries) { + console.log('Retrying...'); + } else { + console.log('Maximum retries reached. Exiting.'); + process.exit(1); + } + } + } +} + +const maxRetries = process.argv[2]; +const command = process.argv.slice(3).join(' '); + +if (!maxRetries || !command) { + console.log('Usage: node retry_script.js '); + process.exit(1); +} + +retryCommand(maxRetries, command); diff --git a/scripts/retry3 b/scripts/retry3 deleted file mode 100755 index 2f96c6f997cc8c..00000000000000 --- a/scripts/retry3 +++ /dev/null @@ -1,24 +0,0 @@ -#!/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