Repository navigation
311 lines (261 loc) · 11.4 KB
/
Copy pathci.yml
File metadata and controls
311 lines (261 loc) · 11.4 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
name: CI
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
jobs:
frontend:
name: Frontend (typecheck / lint / format / test / build)
# 视觉基线只在 Linux 维护(见 playwright.config.ts 的说明)。
# Windows 渲染会让同一份基线稳定漂移 1-3%,把平台无关的检查放在
# Ubuntu 上,Windows 兼容性交给下面的 backend-windows 作业。
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: "22.22.2"
cache: npm
- run: npm ci
# 图标必须是透明圆角:源图是白底 JPEG,忘了抠会给深色界面
# 留下一圈白方块,这不在任何类型检查的覆盖范围内。
# runner 自带的 python 没有 Pillow,必须先装,否则这一步只会
# 报 ModuleNotFoundError —— 门禁变成噪音。
- name: Install Pillow
run: python -m pip install --disable-pip-version-check pillow
- name: Icon contract
run: python scripts/check_icons.py
# 版本号出现在 package / lock / Tauri / Cargo 多处;任何一处漏改都会
# 让应用内版本、安装包文件名和 Release 标题各说各话。
- name: Version consistency
run: npm run version:check
- name: Typecheck
run: npx tsc --noEmit
- name: Lint
run: npm run lint
# 依赖方向 / pages 越层引用 / Tauri core 泄漏,这些不会被 eslint 或 tsc
# 拦住,必须在 CI 里单独跑;否则本地门禁只是「建议」,合并后照样漂。
- name: Module boundaries
run: npm run check:modules
# 供应链门禁:生产依赖出现 >= high 的已知漏洞即失败。
# 显式钉官方 registry:镜像(如 npmmirror)不实现 audit 接口,
# 会在“看起来跑过了”的情况下拿不到任何结论。
- name: Audit (prod deps)
run: npm audit --omit=dev --audit-level=high --registry=https://registry.npmjs.org
- name: Format check
run: npm run format:check
# 重复代码:阈值 3%(与审查红线一致)。jscpd 退出码非 0 即超阈值。
- name: Duplication
run: npm run dup
# coverage 跑的就是单元测试;阈值写在 vitest.config.mts,只有带
# --coverage 时才生效,所以这里是唯一入口,不重复跑两遍测试。
- name: Unit tests + coverage
run: npm run coverage
- name: Build
run: npm run build
# 视觉回归:捕获布局塌陷、图表标签重叠、元素不可见这类问题。
# 单元测试和类型检查对它们完全无感。
# 字体必须钉死:基线里有中文,缺 Noto CJK 时 Chromium 会退到
# 文泉驿等系统字体,字重和度量不同,整页文本都会判成差异。
- name: Install Playwright browser
run: npx playwright install --with-deps chromium
- name: Install CJK fonts
run: sudo apt-get update && sudo apt-get install -y fonts-noto-cjk
- name: Visual regression
run: npm run test:e2e
env:
CI: "true"
- name: Upload visual diffs
if: failure()
uses: actions/upload-artifact@v7
with:
name: visual-diffs
path: |
test-results/
e2e/visual.spec.ts-snapshots/
retention-days: 7
# Linux 后端:平台差异(端口采集、进程保护、路径归一)必须在这里被真正跑到。
# 之前只有 Windows runner,导致「Linux 白名单恒为空」「LISTEN/LISTENING 不一致」
# 这类问题无法被发现。
backend-linux:
name: Backend (Linux)
# 与发布构建保持一致:Ubuntu 24.04 编出的二进制要求 glibc 2.38+,
# 在 22.04 / Debian 12 等常见环境上会直接起不来。
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v7
- name: Install Tauri system deps
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev librsvg2-dev libayatana-appindicator3-dev patchelf libssl-dev pkg-config
- uses: dtolnay/rust-toolchain@1.95.0
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri
# Swatinem 的默认 key 只区分 linux/macOS/windows,不区分 Ubuntu 版本;
# 24.04 的 target 缓存拿到 22.04 上会缺依赖、报 cannot find crate。
key: ubuntu-22.04
- uses: actions/setup-node@v7
with:
node-version: "22.22.2"
cache: npm
# rust-embed 在编译期读取 ../dist(0.7.1 起前端产物嵌入 exe)。
# backend job 与前端 job 分离,不先构建前端的话 derive 宏直接报
# folder does not exist —— 0.7.1 首次 CI 三平台齐红的实测根因。
# 顺带让 CI 测试的正是「带嵌入 UI 的真实产物」,而不是残缺版本。
- name: Build frontend for embedding
run: |
npm ci
npm run build
- name: Format check
working-directory: src-tauri
run: cargo fmt --all -- --check
- name: Tests
working-directory: src-tauri
run: cargo test
- name: Clippy
working-directory: src-tauri
run: cargo clippy --all-targets -- -D warnings
# Rust 供应链门禁:RUSTSEC 有已知漏洞即失败。cargo-audit 不随工具链
# 预装,钉版本避免上游更新让门禁行为漂移。0.22.x 起支持解析
# advisory-db 里的 CVSS 4.0 公告(0.21.2 会直接 parse error)。
- name: Install cargo-audit
run: cargo install cargo-audit --locked --version 0.22.2
- name: Audit (Rust deps)
working-directory: src-tauri
run: cargo audit
# 打包验证:确保 deb 真的能产出。仅编译不打包时,
# productName/包名/图标布局这类问题不会被发现。
- uses: actions/setup-node@v7
with:
node-version: "22.22.2"
cache: npm
- run: npm ci
- name: Build deb package
run: npx tauri build --bundles deb --config src-tauri/tauri.ci.conf.json
- name: Verify deb structure
run: |
deb=$(ls src-tauri/target/release/bundle/deb/*.deb | head -1)
echo "built: $deb"
dpkg-deb -c "$deb" | grep -q "usr/bin/workbench" || { echo "binary missing"; exit 1; }
dpkg-deb -f "$deb" Package | grep -Eq '^[a-z0-9][a-z0-9.+-]*$' || { echo "invalid package name"; exit 1; }
# 产物上传:README 里「取 CI 的 linux-deb artifact」必须是真的可下载,
# 否则又是一句没有兑现的声明。
- name: Upload deb
uses: actions/upload-artifact@v7
with:
name: linux-deb
path: src-tauri/target/release/bundle/deb/*.deb
if-no-files-found: error
retention-days: 14
# macOS:代码里所有平台差异都走 `cfg`,但从未真正编译过。
# 公开仓库的 macOS runner 免费;跑一次就能把「未验证」变成「每 commit 验证」。
# 产物不签名(需要付费证书),所以只验证能编译、能跑测试、能打出 .app。
backend-macos:
name: Backend (macOS)
runs-on: macos-latest
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@1.95.0
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri
# Swatinem 的默认 key 只区分 linux/macOS/windows,不区分 Ubuntu 版本;
# 24.04 的 target 缓存拿到 22.04 上会缺依赖、报 cannot find crate。
key: ubuntu-22.04
- uses: actions/setup-node@v7
with:
node-version: "22.22.2"
cache: npm
# rust-embed 在编译期读取 ../dist(0.7.1 起前端产物嵌入 exe)。
# backend job 与前端 job 分离,不先构建前端的话 derive 宏直接报
# folder does not exist —— 0.7.1 首次 CI 三平台齐红的实测根因。
# 顺带让 CI 测试的正是「带嵌入 UI 的真实产物」,而不是残缺版本。
- name: Build frontend for embedding
run: |
npm ci
npm run build
- name: Format check
working-directory: src-tauri
run: cargo fmt --all -- --check
- name: Tests
working-directory: src-tauri
run: cargo test
- name: Clippy
working-directory: src-tauri
run: cargo clippy --all-targets -- -D warnings
- uses: actions/setup-node@v7
with:
node-version: "22.22.2"
cache: npm
- run: npm ci
- name: Build app bundle
run: npx tauri build --bundles app --config src-tauri/tauri.ci.conf.json
- name: Verify bundle structure
run: |
app=$(ls -d src-tauri/target/release/bundle/macos/*.app | head -1)
echo "built: $app"
test -x "$app/Contents/MacOS/workbench" || { echo "binary missing"; exit 1; }
test -f "$app/Contents/Info.plist" || { echo "Info.plist missing"; exit 1; }
- name: Upload app bundle
uses: actions/upload-artifact@v7
with:
name: macos-app
path: src-tauri/target/release/bundle/macos/*.app
if-no-files-found: error
retention-days: 14
backend:
name: Backend (Windows)
runs-on: windows-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: "22.22.2"
- uses: dtolnay/rust-toolchain@1.95.0
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri
# rust-embed 在编译期读取 ../dist(0.7.1 起前端产物嵌入 exe)。
# backend job 与前端 job 分离,不先构建前端的话 derive 宏直接报
# folder does not exist —— 0.7.1 首次 CI 三平台齐红的实测根因。
# 顺带让 CI 测试的正是「带嵌入 UI 的真实产物」,而不是残缺版本。
- name: Build frontend for embedding
run: |
npm ci
npm run build
- name: Format check
working-directory: src-tauri
run: cargo fmt --all -- --check
- name: Tests
working-directory: src-tauri
run: cargo test
- name: Clippy
working-directory: src-tauri
run: cargo clippy --all-targets -- -D warnings
# ts-rs 导出是契约快照:Rust 结构体改了但忘记重新导出时,
# 前端类型会静默漂移。重新生成后必须**零改动**才算通过。
# 用 git status 而不是 git diff:新增的生成文件是未跟踪状态,
# git diff 看不到它们,而「新增结构体但忘了提交生成物」正是最常见形态。
- name: IPC contract drift
working-directory: src-tauri
shell: bash
run: |
cargo test --test export_bindings
if [ -n "$(git status --porcelain -- ../src/generated)" ]; then
echo "::error::src/generated 与 Rust 结构体不一致,请运行 cargo test --test export_bindings 并提交生成结果"
git status --porcelain -- ../src/generated
git diff -- ../src/generated
exit 1
fi
- name: Install frontend deps
run: npm ci
- name: Typecheck generated contract
run: npx tsc --noEmit