mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-06 04:00:06 +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/移动端支持要求)
192 lines
5.0 KiB
YAML
192 lines
5.0 KiB
YAML
name: Release CI/CD Pipeline
|
||
|
||
on:
|
||
push:
|
||
tags:
|
||
- 'v*'
|
||
|
||
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: 30
|
||
|
||
# ============================================
|
||
# 阶段 5: Docker 构建与发布 (仅 tag)
|
||
# ============================================
|
||
docker-build:
|
||
runs-on: ubuntu-latest
|
||
name: Docker Build & Push
|
||
needs: e2e-test
|
||
# 只在 tag 推送时构建镜像
|
||
if: startsWith(github.ref, 'refs/tags/v')
|
||
permissions:
|
||
contents: read
|
||
packages: write
|
||
|
||
steps:
|
||
- name: Checkout repository
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Log in to GitHub Container Registry
|
||
uses: docker/login-action@v3
|
||
with:
|
||
registry: ghcr.io
|
||
username: ${{ github.actor }}
|
||
password: ${{ secrets.GITHUB_TOKEN }}
|
||
|
||
# 提取 Docker 元数据(自动生成版本标签)
|
||
- name: Extract Docker metadata
|
||
id: meta
|
||
uses: docker/metadata-action@v5
|
||
with:
|
||
images: ghcr.io/${{ github.repository }}
|
||
tags: |
|
||
# Git Tag v1.0.0 → 1.0.0, 1.0, 1
|
||
type=semver,pattern={{version}}
|
||
type=semver,pattern={{major}}.{{minor}}
|
||
type=semver,pattern={{major}}
|
||
# 正式版本 tag(不含 -beta/-rc 等后缀)→ latest
|
||
type=raw,value=latest,enable=${{ !contains(github.ref, '-') }}
|
||
# 所有推送 → sha-abc1234
|
||
type=sha,prefix=sha-
|
||
|
||
# 设置 QEMU 模拟器(多架构支持)
|
||
- name: Set up QEMU (Enable multi-arch)
|
||
uses: docker/setup-qemu-action@v3
|
||
|
||
- name: Set up Docker Buildx
|
||
uses: docker/setup-buildx-action@v3
|
||
|
||
- name: Build and push Docker image
|
||
uses: docker/build-push-action@v5
|
||
with:
|
||
context: .
|
||
push: true
|
||
platforms: linux/amd64,linux/arm64
|
||
tags: ${{ steps.meta.outputs.tags }}
|
||
labels: ${{ steps.meta.outputs.labels }}
|
||
cache-from: type=gha
|
||
cache-to: type=gha,mode=max |