|
| 1 | +import { spawnSync } from 'node:child_process' |
| 2 | +import process from 'node:process' |
| 3 | + |
| 4 | +/** |
| 5 | + * Windows CI runners intermittently crash while spawning devframe's native |
| 6 | + * build toolchain (rolldown, via tsdown/vite) with |
| 7 | + * `STATUS_DLL_INIT_FAILED` (exit code -1073741502, surfaced by pnpm/turbo |
| 8 | + * as 3221225794) under `turbo run build`'s concurrency — an environment |
| 9 | + * fault unrelated to the code under test. `unit-test / test |
| 10 | + * (windows-latest, *)` in the "CI" workflow has failed on this signature |
| 11 | + * across many unrelated commits and packages. |
| 12 | + * |
| 13 | + * Retries the given command a bounded number of times instead of failing |
| 14 | + * the run on this class of transient crash. A genuine compile error fails |
| 15 | + * the same way on every attempt, so it still surfaces after the retry |
| 16 | + * budget is spent. |
| 17 | + */ |
| 18 | + |
| 19 | +const [, , ...commandParts] = process.argv |
| 20 | +if (commandParts.length === 0) { |
| 21 | + console.error('Usage: tsx scripts/ci-retry.ts <command...>') |
| 22 | + process.exit(1) |
| 23 | +} |
| 24 | + |
| 25 | +const command = commandParts.join(' ') |
| 26 | +const attempts = Number(process.env.CI_RETRY_ATTEMPTS ?? 3) |
| 27 | +const delayMs = Number(process.env.CI_RETRY_DELAY_MS ?? 5000) |
| 28 | + |
| 29 | +function sleep(ms: number): Promise<void> { |
| 30 | + return new Promise(resolve => setTimeout(resolve, ms)) |
| 31 | +} |
| 32 | + |
| 33 | +async function main(): Promise<void> { |
| 34 | + for (let attempt = 1; attempt <= attempts; attempt++) { |
| 35 | + const result = spawnSync(command, { stdio: 'inherit', shell: true }) |
| 36 | + if (result.status === 0) |
| 37 | + return |
| 38 | + |
| 39 | + const code = result.status ?? result.signal ?? 'unknown' |
| 40 | + const isLastAttempt = attempt === attempts |
| 41 | + console.error(`\n[ci-retry] \`${command}\` failed (exit ${code}), attempt ${attempt}/${attempts}${isLastAttempt ? '' : ` — retrying in ${delayMs}ms`}\n`) |
| 42 | + |
| 43 | + if (isLastAttempt) |
| 44 | + process.exit(typeof result.status === 'number' ? result.status : 1) |
| 45 | + |
| 46 | + await sleep(delayMs) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +main() |
0 commit comments