Repository navigation
111 lines (101 loc) · 3.93 KB
/
Copy pathe2e.yml
File metadata and controls
111 lines (101 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: e2e
# 特性分支 / PR 的测试门禁(master 由 build_book.yml 负责构建+测试+部署)
# 取代原 test_build_book.yml(仅构建): 这里构建 + 跑 vitest + Playwright E2E
on:
push:
branches: [ '**', '!master', '!gh-pages' ]
pull_request:
schedule:
# 夜间额外跑 @prod(SW/离线) 与 @network(真实 Algolia/ES) 这一层(默认分支 master)
- cron: '0 18 * * *'
# 同一分支新推送时取消在跑的旧 run 省 PR 分钟数
concurrency:
group: e2e-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
unit:
# 纯逻辑/组件层: 快、无浏览器、无密钥 几秒出结果
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24.x
cache: npm
- run: npm ci
- name: vitest (unit + component)
run: npm test
# 构建一次, 把产物 dist 共享给所有 E2E 分片 —— 避免每个分片各跑一遍最贵的 npm run build(逐 .md git log)
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: '0' # 必须: GitService 对每个 .md 跑 git log 生成 *.md.json/统计 浅克隆会得到 1999 兜底日期
- uses: actions/setup-node@v7
with:
node-version: 24.x
cache: npm
- run: npm ci
- name: Build (prod, deterministic)
# NOTE_BUILD_COMMIT_TOTAL_TREND=1 跳过 CommitTotalTrendGenerator 对 gh-pages 的 3 次重试拉取(最大网络抖动源)
env:
NOTE_BUILD_COMMIT_TOTAL_TREND: '1'
run: npm run build
- name: Upload dist artifact
uses: actions/upload-artifact@v7
with:
name: dist
path: dist
retention-days: 1
include-hidden-files: true # 保留 .nojekyll 等点文件
e2e:
needs: build # 复用 build 产物 不在此重新构建
runs-on: ubuntu-latest
strategy:
fail-fast: false # 一个分片失败不掩盖其他分片
matrix:
shard: [1, 2, 3] # 各分片复用同一份已构建 dist 并行跑 1/3 用例(套件变大再加分片)
steps:
- uses: actions/checkout@v7 # 仅需测试代码与配置 不在此构建 故无需 fetch-depth:0
- uses: actions/setup-node@v7
with:
node-version: 24.x
cache: npm
- run: npm ci
- name: Resolve Playwright version
id: pw
run: echo "v=$(node -p "require('@playwright/test/package.json').version")" >> "$GITHUB_OUTPUT"
- name: Cache Playwright browsers
uses: actions/cache@v6
with:
path: ~/.cache/ms-playwright
key: pw-${{ runner.os }}-${{ steps.pw.outputs.v }}
- name: Install Chromium (+ OS deps)
run: npx playwright install --with-deps chromium
- name: Download dist artifact
uses: actions/download-artifact@v8
with:
name: dist
path: dist
- name: E2E (shard ${{ matrix.shard }}/3)
# npm run serve(vite preview)直接服务已下载的 dist 不重新构建; fixtures 也从 dist/category.json 发现夹具
# PR/push: 只跑确定性、无密钥的门禁层(排除 @prod/@network)
# schedule(夜间): 跑全量含 @prod(SW/离线)/@network(真实 Algolia, 凭据是硬编码公开 search key, 无需密钥)
run: |
if [ "${{ github.event_name }}" = "schedule" ]; then
npx playwright test --shard=${{ matrix.shard }}/3
else
npx playwright test --shard=${{ matrix.shard }}/3 --grep-invert "@prod|@network"
fi
- name: Upload report + traces (on failure)
if: failure()
uses: actions/upload-artifact@v7
with:
name: playwright-report-shard-${{ matrix.shard }}
path: |
playwright-report/
test-results/
retention-days: 7