ci / 质量门禁 (push) Successful in 5m3s
背景:run #42 第 10 步「数据库迁移与幂等种子」失败,Prisma 报 P1001: Can't reach database server at 127.0.0.1:5432。 原因:job 运行在容器里,service 容器不能用 127.0.0.1 访问;act_runner 会为 service 容器在 job 网络里加别名,须用 <service-id>:<port>。 改动:DATABASE_URL 改为 @postgres:5432,REDIS_URL 改为 //redis:6379,并注释说明。 影响面:仅 CI job env;本地与生产连接串不变。 回滚方式:revert 本提交。 验证证据:推送后观察 run #43 的迁移 / 集成测试步骤。
133 lines
3.7 KiB
YAML
133 lines
3.7 KiB
YAML
# 自建 Gitea 已部署 Actions runner(gitea-runner-01,label ubuntu-latest):
|
||
# push main 自动执行,也可在 Actions 页面手动触发。轻量冒烟见 ci-smoke.yml。
|
||
# 本地等价命令:pnpm ci:local(推送前仍必须全绿,远端 CI 是第二道防线)。
|
||
name: ci
|
||
|
||
on:
|
||
push:
|
||
branches: [main]
|
||
workflow_dispatch:
|
||
|
||
concurrency:
|
||
group: ci-${{ github.ref }}
|
||
cancel-in-progress: true
|
||
|
||
jobs:
|
||
verify:
|
||
name: 质量门禁
|
||
runs-on: ubuntu-latest
|
||
timeout-minutes: 30
|
||
|
||
services:
|
||
postgres:
|
||
image: postgres:18-alpine
|
||
env:
|
||
POSTGRES_USER: postgres
|
||
POSTGRES_PASSWORD: postgres
|
||
POSTGRES_DB: lingxi_test
|
||
ports:
|
||
- 5432:5432
|
||
options: >-
|
||
--health-cmd "pg_isready -U postgres -d lingxi_test"
|
||
--health-interval 5s
|
||
--health-timeout 3s
|
||
--health-retries 10
|
||
redis:
|
||
image: redis:7.4-alpine
|
||
ports:
|
||
- 6379:6379
|
||
options: >-
|
||
--health-cmd "redis-cli ping"
|
||
--health-interval 5s
|
||
--health-timeout 3s
|
||
--health-retries 10
|
||
|
||
env:
|
||
NODE_ENV: test
|
||
LOG_LEVEL: error
|
||
# job 运行在容器里:service 容器用 <service-id>:<port> 访问,不能用 127.0.0.1。
|
||
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/lingxi_test?schema=public
|
||
REDIS_URL: redis://redis:6379
|
||
JWT_ACCESS_SECRET: ci-only-access-secret-at-least-32-chars
|
||
JWT_REFRESH_SECRET: ci-only-refresh-secret-at-least-32-chars
|
||
WEB_ORIGIN: http://127.0.0.1:4173
|
||
PLAYWRIGHT_CHANNEL: ''
|
||
|
||
steps:
|
||
- name: 检出代码
|
||
uses: actions/checkout@v4
|
||
|
||
- name: 安装 pnpm
|
||
uses: pnpm/action-setup@v4
|
||
with:
|
||
version: 10.34.9
|
||
|
||
- name: 安装 Node.js
|
||
uses: actions/setup-node@v4
|
||
with:
|
||
node-version: 24.15.0
|
||
cache: pnpm
|
||
|
||
- name: 安装依赖
|
||
run: pnpm install --frozen-lockfile
|
||
|
||
# workspace 包的 types 指向 dist/(gitignore),全新检出必须先构建,
|
||
# 否则 Lint 的类型感知规则会报 type that cannot be resolved。
|
||
- name: 构建 workspace 包(Lint 类型解析前置)
|
||
run: pnpm exec turbo run build --filter='./packages/*'
|
||
|
||
- name: 格式检查
|
||
run: pnpm format:check
|
||
|
||
- name: Lint
|
||
run: pnpm lint
|
||
|
||
- name: 类型检查
|
||
run: pnpm typecheck
|
||
|
||
- name: 单元测试与覆盖率
|
||
run: pnpm test
|
||
|
||
# VITE_PUBLIC_DEMO_SESSION 只给构建 / e2e,避免污染单测里对真实登录流程的断言。
|
||
- name: 构建
|
||
env:
|
||
VITE_PUBLIC_API_BASE_URL: http://127.0.0.1:3000/api/v1
|
||
VITE_PUBLIC_DEMO_SESSION: 'true'
|
||
run: pnpm build
|
||
|
||
- name: 数据库迁移与幂等种子
|
||
run: |
|
||
pnpm exec prisma migrate deploy
|
||
pnpm db:seed
|
||
|
||
- name: 集成测试
|
||
run: pnpm test:int
|
||
|
||
- name: 导出 OpenAPI 快照并检查破坏性变更
|
||
run: |
|
||
pnpm openapi:export
|
||
pnpm openapi:diff
|
||
|
||
- name: 安装 Playwright 浏览器
|
||
run: pnpm exec playwright install --with-deps chromium
|
||
|
||
- name: 端到端冒烟
|
||
env:
|
||
VITE_PUBLIC_API_BASE_URL: http://127.0.0.1:3000/api/v1
|
||
VITE_PUBLIC_DEMO_SESSION: 'true'
|
||
run: pnpm test:e2e
|
||
|
||
- name: 归档测试产物
|
||
if: always()
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: test-artifacts
|
||
if-no-files-found: ignore
|
||
path: |
|
||
coverage
|
||
apps/*/coverage
|
||
packages/*/coverage
|
||
test-results
|
||
playwright-report
|
||
openapi/lingxi.openapi.json
|