mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-05 21:09:34 +08:00
## CI/CD 改进 - 在 ci-e2e.yml 添加 build-check 阶段,确保构建验证在 E2E 测试前完成 - 统一 Playwright 报告保留时间:开发环境 7 天,发布环境 30 天 - 移除 ci.yml 的 workflow_dispatch 手动触发,简化发布流程 ## 安全加固 - 启用 /api/analyze 和 /api/reanswer 的认证检查,防止未授权访问 ## 日志系统升级 - 引入 pino 高性能日志库(10.1.0)替代 console.log - 创建统一的日志工具 src/lib/logger.ts - 重构核心 AI API 日志: * /api/analyze: 替换 9 处 console 调用 * /api/reanswer: 替换 4 处 console 调用 - 新增 LOG_LEVEL 环境变量配置 ## 开发规范 - 更新 .cursorrulers: * 新增 Git 提交规则(禁止自动提交,要求人工确认) * 新增响应式设计规则(PC/移动端支持要求)
144 lines
3.2 KiB
YAML
144 lines
3.2 KiB
YAML
name: CI Test Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
paths:
|
|
- 'src/**'
|
|
- 'package.json'
|
|
- 'package-lock.json'
|
|
- 'prisma/**'
|
|
- 'e2e/**'
|
|
- 'playwright.config.ts'
|
|
pull_request:
|
|
branches: [ main ]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
# ============================================
|
|
# 阶段 1: 单元测试
|
|
# ============================================
|
|
unit-test:
|
|
runs-on: ubuntu-latest
|
|
name: Unit Tests
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '22'
|
|
cache: 'npm'
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Run unit tests
|
|
run: npm run test:unit
|
|
|
|
# ============================================
|
|
# 阶段 2: 集成测试
|
|
# ============================================
|
|
integration-test:
|
|
runs-on: ubuntu-latest
|
|
name: Integration Tests
|
|
needs: unit-test
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '22'
|
|
cache: 'npm'
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Generate Prisma Client
|
|
run: npx prisma generate
|
|
|
|
- name: Run integration tests
|
|
run: npm run test:integration
|
|
|
|
# ============================================
|
|
# 阶段 3: 构建验证 (确保可以构建)
|
|
# ============================================
|
|
build-check:
|
|
runs-on: ubuntu-latest
|
|
name: Build Check
|
|
needs: integration-test
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '22'
|
|
cache: 'npm'
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Generate Prisma Client
|
|
run: npx prisma generate
|
|
|
|
- name: Build application
|
|
run: npm run build
|
|
|
|
# ============================================
|
|
# 阶段 4: E2E 测试 (真实场景验证)
|
|
# ============================================
|
|
e2e-test:
|
|
runs-on: ubuntu-latest
|
|
name: E2E Tests
|
|
needs: build-check
|
|
timeout-minutes: 60
|
|
env:
|
|
DATABASE_URL: "file:./e2e.db"
|
|
NEXTAUTH_SECRET: "ci-secret-value-123456"
|
|
NEXTAUTH_URL: "http://127.0.0.1:3000"
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '22'
|
|
cache: 'npm'
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Install Playwright Browsers
|
|
run: npx playwright install --with-deps
|
|
|
|
- name: Setup Database
|
|
run: |
|
|
npx prisma db push
|
|
npx prisma db seed
|
|
|
|
- name: Build application
|
|
run: npm run build
|
|
|
|
- name: Run Playwright tests
|
|
run: npx playwright test
|
|
env:
|
|
CI: true
|
|
|
|
- name: Upload Playwright Report
|
|
if: failure()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: playwright-report
|
|
path: playwright-report/
|
|
retention-days: 7
|