From 68a7bb64bf39b1b0de4dd0c4220980627b0a7a3f Mon Sep 17 00:00:00 2001 From: yunyingk Date: Wed, 30 Sep 2026 14:16:18 +0800 Subject: [PATCH] Wait for CI checks to register before watching the release PR --- scripts/release.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/release.ts b/scripts/release.ts index dec7406..5f15356 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -63,6 +63,28 @@ function runCapture(cmd: string) { return execSync(cmd, { cwd: ROOT, encoding: "utf-8" }).trim(); } +/** + * `gh pr checks --watch` exits with "no checks reported" when started before GitHub has + * registered the workflow run — a race that hit two consecutive releases seconds after PR + * creation. Poll until at least one check exists, then hand over to --watch. + */ +function waitForFirstCheck(prNumber: string): void { + const maxAttempts = 60; // 60 * 5s = 5 min ceiling; CI normally registers within seconds + for (let attempt = 1; attempt <= maxAttempts; attempt++) { + try { + const output = runCapture(`gh pr checks ${prNumber}`); + if (output.length > 0) return; + } catch { + // "no checks reported" exits non-zero — keep polling + } + if (attempt < maxAttempts) { + console.log(` CI 检查尚未上报,等待中 (${attempt}/${maxAttempts})...`); + spawnSync("sleep", ["5"], { stdio: "ignore" }); + } + } + throw new Error(`等待 PR #${prNumber} 的 CI 检查上报超时(${maxAttempts * 5} 秒)`); +} + // 2. Pre-flight checks console.log("🔍 步骤 1/8: 执行发布前置条件核验..."); @@ -164,6 +186,7 @@ try { if (!prNumber) throw new Error(`无法从 PR URL 中提取 PR 编号: ${prUrl}`); console.log(`⏳ 正在等待 PR #${prNumber} CI 门禁检查跑绿...`); + waitForFirstCheck(prNumber); run(`gh pr checks ${prNumber} --watch`); console.log(`🚀 自动合并 PR #${prNumber} 到 main...`);