mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-03 13:09:27 +08:00
153 lines
3.4 KiB
YAML
153 lines
3.4 KiB
YAML
name: CI Test Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
paths:
|
|
- 'src/**'
|
|
- 'package.json'
|
|
- 'package-lock.json'
|
|
- 'prisma/**'
|
|
- 'e2e/**'
|
|
- 'playwright.config.ts'
|
|
- '.github/workflows/**'
|
|
pull_request:
|
|
branches: [ main ]
|
|
paths:
|
|
- 'src/**'
|
|
- 'package.json'
|
|
- 'package-lock.json'
|
|
- 'prisma/**'
|
|
- 'e2e/**'
|
|
- 'playwright.config.ts'
|
|
- '.github/workflows/**'
|
|
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
|