Skip to content

Commit 9f4dbfa

Browse files
committed
fix(ci): add lighthouse timeout guards to prevent hanging runs
1 parent 821b753 commit 9f4dbfa

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

.github/workflows/ci-quality.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ jobs:
3737
run: npm run ci
3838

3939
- name: Lighthouse Quality Gate
40+
timeout-minutes: 8
4041
env:
4142
LH_MIN_PERFORMANCE: ${{ github.ref == 'refs/heads/master' && '95' || '90' }}
4243
LH_MIN_ACCESSIBILITY: "90"
4344
LH_MIN_BEST_PRACTICES: "90"
4445
LH_MIN_SEO: "100"
4546
LH_SKIP_BUILD: "1"
47+
LH_TIMEOUT_MS: "120000"
4648
run: npm run audit:lighthouse

PROGRESS.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
> 仓库:`/home/zocs/Devs/catcoding-web`
44
> 用途:记录执行复盘、计划更新与下一轮任务
55
6-
## 当前状态(2026-04-28 01:37 CST)
6+
## 当前状态(2026-04-28 08:18 CST)
77

88
- 站点框架:Astro 6,双语页面(`/` + `/zh/`
99
- 质量门禁:`npm run ci` 通过(`astro check` + `astro build`
@@ -135,6 +135,15 @@
135135
- 实施:`ci-quality.yml``setup-node` 增加 `cache-dependency-path: package-lock.json`
136136
- 预期收益:runner 缓存命中更稳定,降低安装阶段耗时抖动
137137

138+
## 本轮执行复盘(2026-04-28 上午第 17 轮)
139+
140+
- code review:远端 `CI Quality` 出现长时间卡在 Lighthouse 步骤的风险
141+
- 实施:
142+
- `lighthouse-baseline.mjs` 为每次 Lighthouse 调用增加进程超时(默认 `LH_TIMEOUT_MS=120000`
143+
- 增加 `--max-wait-for-load=45000`,限制页面加载等待时长
144+
- workflow 的 `Lighthouse Quality Gate` 步骤增加 `timeout-minutes: 8` 并传入 `LH_TIMEOUT_MS`
145+
- 验证:本地 `npm run ci:quality` 通过,分数保持 `P100 / A11y92 / BP96 / SEO100`
146+
138147
## 强制环节(与主仓库对齐)
139148

140149
每轮自动推进必须执行:

scripts/lighthouse-baseline.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ function run(cmd, args, options = {}) {
1414
shell: false,
1515
env: process.env,
1616
});
17+
let timer;
18+
if (options.timeoutMs && Number.isFinite(options.timeoutMs)) {
19+
timer = setTimeout(() => {
20+
child.kill('SIGTERM');
21+
}, options.timeoutMs);
22+
}
1723
child.on('error', reject);
1824
child.on('exit', (code) => {
25+
if (timer) clearTimeout(timer);
1926
if (code === 0) resolve();
2027
else reject(new Error(`${cmd} ${args.join(' ')} failed with code ${code}`));
2128
});
@@ -37,6 +44,7 @@ const thresholds = {
3744
bestPractices: Number(process.env.LH_MIN_BEST_PRACTICES ?? 90),
3845
seo: Number(process.env.LH_MIN_SEO ?? 100),
3946
};
47+
const lighthouseTimeoutMs = Number(process.env.LH_TIMEOUT_MS ?? 120000);
4048

4149
function assertThreshold(route, score) {
4250
const failures = Object.entries(thresholds)
@@ -69,10 +77,11 @@ try {
6977
'--quiet',
7078
'--chrome-flags=--headless=new --no-sandbox',
7179
'--only-categories=performance,accessibility,best-practices,seo',
80+
'--max-wait-for-load=45000',
7281
'--output',
7382
'json',
7483
`--output-path=${outputPath}`,
75-
]);
84+
], { timeoutMs: lighthouseTimeoutMs });
7685
};
7786

7887
await runLighthouse('http://127.0.0.1:4321', reportPaths.home);

0 commit comments

Comments
 (0)