ci / 质量门禁 (push) Canceled after 0s
背景:Gitea 暂未部署 Actions runner,远程 CI 会停留在 queued;本地开发库按约定改用 lingxi / postgres / postgres。 改动: - 新增 pnpm ci:local,按 CI 工作流顺序执行 compose、格式、Lint、类型、单测、构建、迁移种子、集成、OpenAPI 与 e2e; - 新增 scripts/e2e.mjs 管理 vite preview 生命周期,e2e 改为单 worker 避免退出挂起; - openapi:export 生成后自动 Prettier,保持工作区干净; - compose、.env.example、CI services 数据库凭据统一为 postgres/postgres,库名 lingxi; - README、AGENTS、A0 报告同步本地 CI 与数据库说明。 影响面:仅本地开发与 CI 执行方式,无业务代码/接口/数据模型变更;本地库已重建为 lingxi/postgres。 回滚方式:git revert 本提交;数据库需按回滚后的 compose 凭据重新初始化。 验证:pnpm ci:local 全绿(158s),format:check、lint、typecheck、openapi:diff 通过。
61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
||
/**
|
||
* 端到端测试启动器:先起 vite preview,再跑 Playwright,结束后确保关闭预览服务。
|
||
* 不使用 Playwright webServer,避免 vite preview 在部分环境下退出挂起。
|
||
* 用法:pnpm test:e2e(会先执行 build)
|
||
*/
|
||
import { spawn, spawnSync } from 'node:child_process';
|
||
import { setTimeout as delay } from 'node:timers/promises';
|
||
|
||
const baseUrl = 'http://127.0.0.1:4173';
|
||
const pnpm = process.env.npm_execpath ? [process.execPath, process.env.npm_execpath] : ['pnpm'];
|
||
|
||
function runPnpm(args, options = {}) {
|
||
return spawnSync(pnpm[0], [...pnpm.slice(1), ...args], {
|
||
env: process.env,
|
||
stdio: 'inherit',
|
||
...options,
|
||
});
|
||
}
|
||
|
||
const server = spawn(pnpm[0], [...pnpm.slice(1), '--filter', '@lingxi/web', 'preview'], {
|
||
env: process.env,
|
||
stdio: 'ignore',
|
||
detached: true,
|
||
});
|
||
|
||
async function waitForServer(url, timeoutMs = 60_000) {
|
||
const startedAt = Date.now();
|
||
while (Date.now() - startedAt < timeoutMs) {
|
||
try {
|
||
const response = await fetch(url);
|
||
if (response.ok) return;
|
||
} catch {
|
||
// 预览服务尚未就绪,继续重试。
|
||
}
|
||
await delay(500);
|
||
}
|
||
throw new Error(`预览服务在 ${timeoutMs}ms 内未就绪:${url}`);
|
||
}
|
||
|
||
let exitCode = 1;
|
||
try {
|
||
await waitForServer(`${baseUrl}/login`);
|
||
const result = runPnpm(['exec', 'playwright', 'test']);
|
||
exitCode = result.status ?? 1;
|
||
} finally {
|
||
try {
|
||
process.kill(-server.pid, 'SIGTERM');
|
||
} catch {
|
||
// 进程可能已退出。
|
||
}
|
||
await delay(1_000);
|
||
try {
|
||
process.kill(-server.pid, 'SIGKILL');
|
||
} catch {
|
||
// 进程可能已退出。
|
||
}
|
||
}
|
||
|
||
process.exit(exitCode);
|