Skip to content

feat: Enhance CI

feat: Enhance CI #146

Workflow file for this run

name: PR Quality Check
# 触发条件:向 develop 或 main 分支提交 PR 时
on:
pull_request:
branches: [develop, main]
types: [opened, synchronize, reopened, ready_for_review]
issue_comment:
types: [created, edited]
# 增加并发控制,避免重复运行浪费资源
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
# 权限配置 (AI Review 需要写评论权限)
permissions:
contents: write # 👈 必须改为 write (用于提交代码建议/git操作)
pull-requests: write # 用于写评论、修改 PR 描述
issues: write # 👈 新增 (因为 PR 评论在 GitHub 也就是 Issue 评论)
jobs:
# 任务 1: 构建检查 & 单元测试 (并行运行的基础)
quality-check:
name: 🏗️ Build & Unit Test
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 10
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
# ✅ Build Check: 确保能打包,无类型错误
- name: 📦 Build Check
run: pnpm build
# ✅ Unit Test: 全量单元测试
- name: 🧪 Unit Test
run: pnpm test:run
# 任务 2: E2E 冒烟测试 (只跑关键路径)
e2e-smoke:
name: 🎭 E2E Smoke Test
runs-on: ubuntu-latest
needs: quality-check
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 10
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
# 获取 Playwright 版本用于缓存 Key
- name: Get installed Playwright version
id: playwright-version
run: echo "PLAYWRIGHT_VERSION=$(pnpm ls @playwright/test --json | jq '.[0].version' -r)" >> $GITHUB_ENV
# 缓存浏览器二进制文件
- name: Cache playwright binaries
uses: actions/cache@v4
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
# 只有缓存未命中才安装浏览器
# 如果缓存命中,仍然需要运行 install-deps (只安装系统依赖)
# 因为缓存只存了浏览器二进制文件 (~/.cache/ms-playwright),没存 apt-get 安装的系统库!
- name: Install Playwright Browsers
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: pnpm exec playwright install --with-deps
- name: Install Playwright System Dependencies
if: steps.playwright-cache.outputs.cache-hit == 'true'
run: pnpm exec playwright install-deps
- name: 🚀 Run Smoke Tests
run: pnpm exec playwright test --grep @smoke
# 任务 3: AI 代码审查 (Non-blocking)
ai-review:
name: 🤖 AI Code Review
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request' ||
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '/review'))
continue-on-error: true # ✅ 关键:即使 AI 报错或超时,也不阻止 PR 合并
# ⚠️ 权限必须配置!PR-Agent 需要比普通 Reviewer 更高的权限
permissions:
issues: write # 允许在 PR 里发评论
pull-requests: write # 允许修改 PR 详情(如自动填 Description)
contents: write # 允许提交代码建议
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Qodo-AI PR-Agent
uses: qodo-ai/pr-agent@main
env:
# API 配置
OPENAI_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_BASE: https://api.gptapi.us/v1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 模型配置
config.model: "openai/deepseek-chat"
config.fallback_models: '["openai/deepseek-r1","openai/deepseek-r1-0528","openai/deepseek-v3","openai/deepseek-v3.1"]'
config.custom_model_max_tokens: "128000"
# 功能配置
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"
github_action_config.pr_actions: '["opened", "reopened", "ready_for_review", "review_requested"]'