Files
lingxi/scripts/ci-local.mjs
T
Stev_Wang 68b5ca20f4
ci / 质量门禁 (push) Canceled after 0s
ci(ci): 支持本地 CI 并调整开发库凭据
背景: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 通过。
2026-11-02 18:14:08 +08:00

51 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* 本地 CI:在无 Gitea Actions runner 时,按 .gitea/workflows/ci.yml 的门禁顺序执行。
* 用法:pnpm ci:local(推荐通过 ./.tools/pnpm ci:local 锁定 pnpm 10)
*/
import { spawnSync } from 'node:child_process';
const pnpm = process.env.npm_execpath ? [process.execPath, process.env.npm_execpath] : ['pnpm'];
/** 每一步可包含多条 pnpm 命令,任一失败立即退出。 */
const steps = [
{ label: '启动本地依赖(PG / Redis / S3)', commands: [['compose:up']] },
{ label: '格式化检查', commands: [['format:check']] },
{ label: 'Lint', commands: [['lint']] },
{ label: '类型检查', commands: [['typecheck']] },
{ label: '单元测试', commands: [['test']] },
{ label: '构建', commands: [['build']] },
{
label: '数据库迁移与种子',
commands: [['exec', 'prisma', 'migrate', 'deploy'], ['db:seed']],
},
{ label: '集成测试', commands: [['test:int']] },
{ label: 'OpenAPI 导出与契约检查', commands: [['openapi:export'], ['openapi:diff']] },
{ label: '端到端测试', commands: [['test:e2e']] },
];
function runPnpm(args) {
const result = spawnSync(pnpm[0], [...pnpm.slice(1), ...args], {
env: process.env,
stdio: 'inherit',
});
if (result.error) {
console.error(`\n执行 pnpm ${args.join(' ')} 失败:${result.error.message}`);
process.exit(1);
}
if (result.status !== 0) {
console.error(`\n门禁失败:pnpm ${args.join(' ')}(exit ${result.status ?? 1})`);
process.exit(result.status ?? 1);
}
}
const startedAt = Date.now();
for (const [index, step] of steps.entries()) {
console.log(`\n[${index + 1}/${steps.length}] ${step.label}`);
for (const args of step.commands) {
runPnpm(args);
}
}
const seconds = ((Date.now() - startedAt) / 1000).toFixed(1);
console.log(`\n本地 CI 全部门禁通过,用时 ${seconds}s。`);