name: CI on: push: branches: [main, master] pull_request: jobs: build-test: name: 类型检查 / 单元测试 / 构建 runs-on: ubuntu-latest services: postgres: # 使用含 pgvector 扩展的镜像(相似项目向量搜索迁移依赖) image: pgvector/pgvector:pg16 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: riskagent ports: - 5432:5432 options: >- --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5 env: DATABASE_URL: postgresql://postgres:postgres@localhost:5432/riskagent # CI 不配置 LLM/AUTH:评估自动回退确定性规则引擎,RBAC 为演示模式 DASHSCOPE_API_KEY: '' AUTH_SECRET: '' steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 cache: npm - name: 安装依赖 run: npm ci - name: 运行数据库迁移 run: npm run migrate:up - name: 类型检查(前后端) run: npm run typecheck - name: 单元 / 属性测试 run: npm test - name: 构建 run: npm run build e2e: name: 端到端(API 全流程) runs-on: ubuntu-latest needs: build-test services: postgres: image: pgvector/pgvector:pg16 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: riskagent ports: - 5432:5432 options: >- --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5 env: DATABASE_URL: postgresql://postgres:postgres@localhost:5432/riskagent DASHSCOPE_API_KEY: '' AUTH_SECRET: '' steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 cache: npm - name: 安装依赖 run: npm ci - name: 运行数据库迁移 run: npm run migrate:up - name: 构建 run: npm run build - name: 播种 E2E 所需基础数据(客户档案) run: node scripts/seed-e2e.mjs - name: 启动后端 run: | node dist/server/index.js & echo $! > server.pid for i in $(seq 1 30); do curl -sf http://localhost:3005/api/health && break sleep 1 done - name: 运行端到端测试 run: npm run e2e - name: 关闭后端 if: always() run: kill "$(cat server.pid)" || true