diff --git a/.github/actions/retry-action/action.yml b/.github/actions/retry-action/action.yml new file mode 100644 index 0000000000..19cf5698c3 --- /dev/null +++ b/.github/actions/retry-action/action.yml @@ -0,0 +1,34 @@ +name: Retry action +description: > + Retry a failed action up to a given number of times (by default 3 times). + +inputs: + command: + description: The command or commands to run. + required: true + max-retries: + description: The number of times to retry. Default is 3. + required: false + default: '3' + +runs: + using: composite + steps: + - name: Run command with retries + run: | + command() { + bash -c "${{ inputs.command }}" + } + + for i in $(seq 1 ${{ inputs.max-retries }}); do + echo "Running command (attempt $i)." + if command; then + echo "Command succeeded on attempt $i." + exit 0 + else + echo "Command failed on attempt $i." + fi + done + echo "Command failed after ${{ inputs.max-retries }} attempts." + exit 1 + shell: bash diff --git a/.github/workflows/build-lint-test.yml b/.github/workflows/build-lint-test.yml index dee9bdb81f..15305d5b91 100644 --- a/.github/workflows/build-lint-test.yml +++ b/.github/workflows/build-lint-test.yml @@ -25,7 +25,10 @@ jobs: with: node-version: ${{ matrix.node-version }} cache: yarn - - run: yarn --immutable + - name: Install Yarn dependencies + uses: ./.github/actions/retry-action + with: + command: yarn --immutable - name: Cache "@metamask/snaps-execution-environments" build id: cache-snaps-execution-environments-build uses: actions/cache@v4