From 668cfc5f70dbfc7795c5cbe1691f8ba2481c9cc7 Mon Sep 17 00:00:00 2001 From: phcorp <725023+phcorp@users.noreply.github.com> Date: Mon, 30 Nov 2026 09:35:26 +0100 Subject: [PATCH] ci: tolerate a concurrent rerun and transient artifact upload errors --- .github/workflows/ci.yml | 10 ++++++++++ docs/releasing.md | 2 +- scripts/lib/RunnerRetry.php | 10 ++++++++-- scripts/runner-retry.php | 20 +++++++++++++------- tests/tools/RunnerRetryTest.php | 25 +++++++++++++++++++++---- 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c2bf7d..87d0ecc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -140,7 +140,10 @@ jobs: CLANG_PATH: /usr/bin/clang-23 LIBCLANG_PATH: /usr/lib/llvm-23/lib PROFILER_COVERAGE_TOOLCHAIN: nightly-2026-11-11 + # Diagnostic artifacts: no job downloads them, so a transient upload error (seen as + # ECONNRESET) must not fail a run whose checks passed. Every upload below does the same. - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + continue-on-error: true if: always() with: name: coverage @@ -183,6 +186,7 @@ jobs: extensions: pdo_sqlite, curl, pcntl, ffi, posix - run: scripts/php-tool.sh scripts/rust-mutation.php --timeout 240 --jobs 2 --shard '${{ strategy.job-index }}/${{ strategy.job-total }}' - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + continue-on-error: true if: always() with: name: mutants-${{ matrix.shard }} @@ -241,11 +245,13 @@ jobs: if test -d "$directory"; then sudo chown -R "$(id -u):$(id -g)" "$directory"; fi done - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + continue-on-error: true if: always() with: name: compatibility-${{ matrix.php }}-${{ matrix.sapi }} path: target/compatibility - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + continue-on-error: true if: always() && matrix.sapi != 'apache' && !startsWith(matrix.sapi, 'frankenphp') with: name: performance-${{ matrix.php }}-${{ matrix.sapi }} @@ -312,6 +318,7 @@ jobs: scripts/c-mutation.sh ' - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + continue-on-error: true if: always() with: name: c-mutation-${{ matrix.zts }} @@ -342,6 +349,7 @@ jobs: if test -d "$directory"; then sudo chown -R "$(id -u):$(id -g)" "$directory"; fi done - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + continue-on-error: true if: always() with: name: clang-c-coverage-${{ matrix.sapi }} @@ -408,6 +416,7 @@ jobs: toolchain: '1.99.1' - run: scripts/php-tool.sh scripts/vendor-patch-mutation.php - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + continue-on-error: true if: always() with: name: vendored-ownership-mutation-${{ matrix.php }} @@ -433,6 +442,7 @@ jobs: if test -d "$directory"; then sudo chown -R "$(id -u):$(id -g)" "$directory"; fi done - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + continue-on-error: true if: always() with: name: zts-sampling-isolation diff --git a/docs/releasing.md b/docs/releasing.md index 3153774..ee440ac 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -16,7 +16,7 @@ Privileged orchestration checks out trusted main, never candidate scripts. Candi Bot-dispatched quality runs explicitly dispatch the trusted-main release workflow from a small continuation job after `quality-gate` passes. They do not rely on a recursively triggered `workflow_run` event. The release entry point receives only the quality run ID, waits a bounded interval for that upstream run to become terminal, and independently checks its successful result, repository, source, branch, actor, and candidate transition. This wait handles the continuation job briefly keeping its own workflow in progress. Ordinary successful main push runs also retain the `workflow_run` entry point; serialized, idempotent orchestration makes retries safe. -GitHub sometimes never assigns a hosted runner to a job, most often on macOS. Such a job is cancelled before its first step, and `quality-gate` fails without anything having been tested. The `runner-retry` workflow then reruns the run's failed jobs, at most twice, but only when every failed job other than `quality-gate` and `release-continuation` was cancelled with no runner and no step, and only while the run's commit is still its branch head: a rerun of a push or pull request run joins its branch's concurrency group and would cancel a newer run. A dispatched release run has its own group, so pushes never cancel it. The rerun includes the dependent `quality-gate` and `release-continuation` jobs, so a dispatched run continues as usual. A rerun's completion is caused by the default token and may start no workflow, so the retry job waits for each rerun itself, retries again if needed, and dispatches the release when a main push run passes on a rerun; serialized, idempotent orchestration makes a second trigger harmless. If the wait runs out, `gh workflow run release.yml --ref main -f quality_run_id=` continues from the successful run. +GitHub sometimes never assigns a hosted runner to a job, most often on macOS. Such a job is cancelled before its first step, and `quality-gate` fails without anything having been tested. The `runner-retry` workflow then reruns the run's failed jobs, at most twice, but only when every failed job other than `quality-gate` and `release-continuation` was cancelled with no runner and no step, and only while the run's commit is still its branch head: a rerun of a push or pull request run joins its branch's concurrency group and would cancel a newer run. A dispatched release run has its own group, so pushes never cancel it. The rerun includes the dependent `quality-gate` and `release-continuation` jobs, so a dispatched run continues as usual. A rerun's completion is caused by the default token and may start no workflow, so the retry job waits for each rerun itself, retries again if needed, and dispatches the release when a main push run passes on a rerun; serialized, idempotent orchestration makes a second trigger harmless. When someone reruns the run between the inspection and the retry job's request, GitHub refuses the second rerun; the job then ends successfully and leaves that attempt to the other rerun, whose completion starts this workflow again. If the wait runs out, `gh workflow run release.yml --ref main -f quality_run_id=` continues from the successful run. These distinctions follow [GitHub's token event policy](https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/trigger-a-workflow), [required-check event restrictions](https://docs.github.com/en/pull-requests/how-tos/merge-and-close-pull-requests/troubleshooting-required-status-checks), and [commit-status API](https://docs.github.com/en/rest/commits/statuses). The exact-source full dispatched run supplies the measured QA result. The held pull-request run never starts and would later show as a failure, so after projecting the status, orchestration deletes the candidate's held `quality` runs from the bot on that exact SHA. A failed lookup or deletion only leaves that run in place; it never stops the release. diff --git a/scripts/lib/RunnerRetry.php b/scripts/lib/RunnerRetry.php index 7a4ab6c..25b83f4 100644 --- a/scripts/lib/RunnerRetry.php +++ b/scripts/lib/RunnerRetry.php @@ -69,7 +69,8 @@ public static function shouldRerun(array $run, array $jobs, string $repository, * * @param Closure(string): mixed $get GETs a repository API path * @param Closure(string): ?string $branchHead the branch's current head, null when gone - * @param Closure(): void $rerun reruns the run's failed jobs + * @param Closure(): bool $rerun reruns the run's failed jobs; false when the run is already + * running again, rerun by someone else between the inspection and the request * @param Closure(): void $continueRelease dispatches the release for this run * @param Closure(int): void $sleep waits that many seconds */ @@ -102,7 +103,12 @@ public static function retry( )) { break; } - $rerun(); + if (!$rerun()) { + // Whoever reran it owns that attempt. A rerun by a person starts this workflow + // again when it completes; one by the default token cannot exist here, since + // this workflow's concurrency group holds one job per run. + return "quality run {$runId} attempt {$attempt}: already rerun elsewhere"; + } $reran = true; for ($poll = 0;; $poll++) { if ($poll === $polls) { diff --git a/scripts/runner-retry.php b/scripts/runner-retry.php index dd9964c..7742bfa 100644 --- a/scripts/runner-retry.php +++ b/scripts/runner-retry.php @@ -10,6 +10,7 @@ use PhpProfiler\Tooling\Arguments; use PhpProfiler\Tooling\Process; +use PhpProfiler\Tooling\ProcessFailedStatus; use PhpProfiler\Tooling\RunnerRetry; $usage = 'runner-retry.php '; @@ -47,13 +48,18 @@ $repository, $get, $branchHead, - static fn() => Process::check([ - 'gh', - 'api', - '--method', - 'POST', - "repos/{$repository}/actions/runs/{$runId}/rerun-failed-jobs", - ]), + static function () use ($repository, $runId): bool { + $command = ['gh', 'api', '--method', 'POST', "repos/{$repository}/actions/runs/{$runId}/rerun-failed-jobs"]; + $result = Process::run($command); + if ($result['status'] === 0) { + return true; + } + // Someone reran the run after it was inspected: GitHub refuses a second rerun. + if (str_contains($result['stdout'] . $result['stderr'], 'This workflow is already running')) { + return false; + } + throw new ProcessFailedStatus($command, $result['status'] ?? -1, $result['stderr']); + }, static fn() => Process::check([ 'gh', 'workflow', diff --git a/tests/tools/RunnerRetryTest.php b/tests/tools/RunnerRetryTest.php index fb63629..4b551e1 100644 --- a/tests/tools/RunnerRetryTest.php +++ b/tests/tools/RunnerRetryTest.php @@ -52,8 +52,13 @@ function unassignedJobs(): array * Runs RunnerRetry::retry() against attempts that follow one another on each rerun; each entry * is [run changes, jobs]. Returns the outcome, the reruns, the release dispatches and sleeps. */ -function retryScenario(array $attempts, array $run = [], int $polls = 330, bool $finishes = true): array -{ +function retryScenario( + array $attempts, + array $run = [], + int $polls = 330, + bool $finishes = true, + bool $accepted = true, +): array { $state = ['attempt' => 0, 'reruns' => 0, 'releases' => 0, 'sleeps' => 0]; $current = static function () use (&$state, $attempts, $run, $finishes): array { [$changes] = $attempts[$state['attempt']]; @@ -77,9 +82,13 @@ function retryScenario(array $attempts, array $run = [], int $polls = 330, bool RETRY_REPOSITORY, $get, static fn(string $branch): ?string => $branch === 'gone' ? null : RETRY_SHA, - static function () use (&$state): void { + static function () use (&$state, $accepted): bool { $state['reruns']++; + if (!$accepted) { + return false; + } $state['attempt']++; + return true; }, static function () use (&$state): void { $state['releases']++; @@ -215,6 +224,13 @@ function passedJobs(): array same([1, 0, 2], [$reruns, $releases, $sleeps]); same('quality run 7: attempt 2 did not complete in time', $outcome); }, + 'a run already rerun elsewhere is left to that rerun' => static function (): void { + // GitHub refuses the request when someone reran the run after it was inspected. + $failed = [['conclusion' => 'failure'], unassignedJobs()]; + [$outcome, $reruns, $releases, $sleeps] = retryScenario([$failed], ['event' => 'push'], accepted: false); + same([1, 0, 0], [$reruns, $releases, $sleeps]); + same('quality run 7 attempt 1: already rerun elsewhere', $outcome); + }, 'unexpected API answers stop without a rerun' => static function (): void { $calls = 0; $never = static function () use (&$calls): void { @@ -258,8 +274,9 @@ function passedJobs(): array RETRY_REPOSITORY, $get, static fn(): string => RETRY_SHA, - static function () use (&$counts): void { + static function () use (&$counts): bool { $counts['reruns']++; + return true; }, static function () use (&$counts): void { $counts['releases']++;