86 lines
2.7 KiB
YAML
86 lines
2.7 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
workflow_dispatch:
|
|
inputs:
|
|
e2e_grep:
|
|
description: 只运行标题匹配该正则的 e2e 用例(留空运行全部)
|
|
required: false
|
|
default: ''
|
|
include_quarantined:
|
|
description: 同时运行在 CI 上被隔离的用例(用于拿 trace 定位)
|
|
type: boolean
|
|
required: false
|
|
default: false
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
# 产品按 Asia/Shanghai 处理日期,部分单元测试断言本地时间字符串;runner 默认 UTC 会失败。
|
|
env:
|
|
TZ: Asia/Shanghai
|
|
|
|
# main 上的推送排队执行而不互相取消,避免频繁的文档提交把前一轮 e2e 取消;PR 内的连续推送仍取消旧运行。
|
|
concurrency:
|
|
group: ci-${{ github.ref }}
|
|
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
|
|
|
jobs:
|
|
check:
|
|
name: 类型检查、单元测试与构建
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 20
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
- uses: actions/setup-node@v7
|
|
with:
|
|
node-version-file: .nvmrc
|
|
cache: npm
|
|
- run: npm ci
|
|
- name: 依赖漏洞审计
|
|
run: npm audit --audit-level=high
|
|
- name: 契约包
|
|
run: npm run check:contracts
|
|
- name: 前端类型检查
|
|
run: npm run typecheck
|
|
- name: 前端单元测试
|
|
run: npx vitest run
|
|
- name: 前端构建
|
|
run: npm run build
|
|
- name: API 类型检查与单元测试
|
|
run: npm run check:api
|
|
- name: API 构建
|
|
run: npm run build:api
|
|
|
|
e2e:
|
|
name: 端到端测试
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 40
|
|
# 需要浏览器且耗时较长,只在主分支推送和手动触发时运行;fork 的 PR 不运行;只改文档的提交(docs: 前缀)跳过。
|
|
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && !startsWith(github.event.head_commit.message, 'docs'))
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
- uses: actions/setup-node@v7
|
|
with:
|
|
node-version-file: .nvmrc
|
|
cache: npm
|
|
- run: npm ci
|
|
- run: npx playwright install --with-deps chrome
|
|
- run: npm run build:contracts
|
|
- run: npx playwright test --project=desktop-chrome ${{ inputs.e2e_grep != '' && format('--grep "{0}"', inputs.e2e_grep) || '' }}
|
|
env:
|
|
CI: 'true'
|
|
E2E_INCLUDE_QUARANTINED: ${{ inputs.include_quarantined == true && '1' || '' }}
|
|
- uses: actions/upload-artifact@v7
|
|
if: failure()
|
|
with:
|
|
name: playwright-report
|
|
path: |
|
|
playwright-report
|
|
test-results
|
|
if-no-files-found: ignore
|
|
retention-days: 7
|