diff --git a/.github/workflows/RerunUnstableFailures.yaml b/.github/workflows/RerunUnstableFailures.yaml index 9db574f989..3fe4de7048 100644 --- a/.github/workflows/RerunUnstableFailures.yaml +++ b/.github/workflows/RerunUnstableFailures.yaml @@ -19,7 +19,7 @@ jobs: actions: write contents: read env: - MAX_FAILED_JOBS: 3 # Maximum number of failed jobs in order to consider rerunning + MAX_FAILED_JOBS: 10 # Maximum number of failed jobs in order to consider rerunning MIN_TOTAL_JOBS: 10 # Minimum number of jobs that has run in order to consider rerunning MAX_ATTEMPTS: 1 # Maximum number of attempts to rerun a failed job steps: diff --git a/build/scripts/RerunUnstableFailures.ps1 b/build/scripts/RerunUnstableFailures.ps1 index eecb01caee..7ba478e3e8 100644 --- a/build/scripts/RerunUnstableFailures.ps1 +++ b/build/scripts/RerunUnstableFailures.ps1 @@ -26,8 +26,20 @@ if ($run.conclusion -ne 'failure') { exit 0 } -if ($run.run_attempt -gt $MaxAttempts) { - Write-Host "Run $RunId is on attempt $($run.run_attempt) (max $MaxAttempts). Skipping." +# For PRs from forks, the first attempt is an approval gate that runs no jobs and +# concludes 'action_required'. This offsets the attempt numbering, so the first real +# build is attempt 2. Discount the gate attempt to compute the effective attempt. +$gateAttempts = 0 +if ($run.run_attempt -gt 1) { + $firstAttemptConclusion = gh api "/repos/$Owner/$Repo/actions/runs/$RunId/attempts/1" --jq '.conclusion' 2>&1 + if ($LASTEXITCODE -eq 0 -and $firstAttemptConclusion -eq 'action_required') { + $gateAttempts = 1 + } +} +$effectiveAttempt = $run.run_attempt - $gateAttempts + +if ($effectiveAttempt -gt $MaxAttempts) { + Write-Host "Run $RunId is on attempt $($run.run_attempt) (effective $effectiveAttempt, max $MaxAttempts). Skipping." exit 0 }