122 lines
2.8 KiB
YAML
122 lines
2.8 KiB
YAML
name: CI Pipeline
|
||
|
||
# 触发条件:只在PR到main分支时运行CI
|
||
on:
|
||
pull_request:
|
||
branches: [ main ]
|
||
push:
|
||
branches: [ main ]
|
||
|
||
jobs:
|
||
# CI 阶段 - 完整的代码质量和测试检查
|
||
ci:
|
||
runs-on: ${{ matrix.os }}
|
||
|
||
strategy:
|
||
fail-fast: false
|
||
matrix:
|
||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||
|
||
steps:
|
||
- name: 检出代码
|
||
uses: actions/checkout@v4
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- name: 启用 Corepack
|
||
run: corepack enable
|
||
|
||
- name: 安装 pnpm
|
||
uses: pnpm/action-setup@v4
|
||
with:
|
||
version: 10.30.3
|
||
|
||
- name: 设置 Node.js
|
||
uses: actions/setup-node@v4
|
||
with:
|
||
node-version-file: ".node-version"
|
||
cache: 'pnpm'
|
||
|
||
- name: 安装依赖
|
||
uses: nick-invision/retry@v3
|
||
with:
|
||
timeout_minutes: 5
|
||
max_attempts: 2
|
||
retry_on: error
|
||
command: pnpm install --frozen-lockfile
|
||
|
||
# 代码质量检查
|
||
- name: Nx Lint
|
||
run: pnpm run lint
|
||
|
||
# 构建(必须在类型检查之前,因为类型定义文件需要通过构建生成)
|
||
- name: Nx Build
|
||
uses: nick-invision/retry@v3
|
||
with:
|
||
timeout_minutes: 10
|
||
max_attempts: 2
|
||
retry_on: error
|
||
command: pnpm run build
|
||
|
||
- name: Nx Type Check
|
||
run: pnpm run typecheck
|
||
|
||
- name: Docs Type Check
|
||
working-directory: ./docs
|
||
run: npx tsc --noEmit
|
||
|
||
- name: 拼写检查 (根目录)
|
||
run: pnpm run spellcheck
|
||
|
||
- name: 代码重复率检查 (monorepo)
|
||
run: pnpm run check:cpd
|
||
|
||
# 测试(构建已在类型检查之前完成)
|
||
- name: Nx Test
|
||
uses: nick-invision/retry@v3
|
||
with:
|
||
timeout_minutes: 10
|
||
max_attempts: 2
|
||
retry_on: error
|
||
command: pnpm run test:coverage
|
||
|
||
# 上传覆盖率(仅 Ubuntu,Node 版本由 .nvmrc 决定)
|
||
- name: 上传覆盖率报告
|
||
uses: codecov/codecov-action@v4
|
||
if: matrix.os == 'ubuntu-latest'
|
||
with:
|
||
token: ${{ secrets.CODECOV_TOKEN }}
|
||
files: |
|
||
./coverage/lcov.info
|
||
flags: unittests
|
||
name: codecov-${{ matrix.os }}
|
||
fail_ci_if_error: true
|
||
verbose: true
|
||
|
||
# CLI 功能测试
|
||
- name: CLI 功能测试
|
||
run: |
|
||
echo "开始 CLI 功能测试..."
|
||
node dist/cli/index.js -v
|
||
node dist/cli/index.js --help
|
||
echo "✅ CLI 功能测试完成"
|
||
|
||
# 上传构建产物
|
||
- name: 上传覆盖率报告
|
||
uses: actions/upload-artifact@v4
|
||
if: always() && matrix.os == 'ubuntu-latest'
|
||
with:
|
||
name: coverage-report-${{ matrix.os }}
|
||
path: |
|
||
coverage/
|
||
retention-days: 30
|
||
|
||
- name: 上传构建产物
|
||
uses: actions/upload-artifact@v4
|
||
if: success()
|
||
with:
|
||
name: build-artifacts-${{ matrix.os }}
|
||
path: |
|
||
dist/
|
||
retention-days: 7
|