执行 ROADMAP 的 S1-P2(npm 分发)与 S1-P3(CI 回归)。
P3 · CI 回归流水线
- .github/workflows/regression.yml:push/PR 自动跑回归,失败阻断
含 playwright 浏览器缓存、零依赖自检、服务就绪轮询、报告上传、
GitHub Step Summary 输出
- tools/run-regression.mjs 重构:
· 路径基于脚本位置(不再依赖 cwd,CI 更稳)
· 环境自检:服务未起退出码 2、playwright 缺失退出码 2
· 断言超时后重试一次(吸取 _collect.html 的偶发教训)
· 超时与断言失败分开统计(timedOut 字段)
· 失败时打印明细并 exit 1,全部通过 exit 0
P2 · npm 分发
- package.json:aurora-admin-design,dependencies 为空(零运行时依赖铁律)
playwright 放 devDependencies(CI 专用)
- tools/build-dist.mjs:零依赖构建脚本,产出 dist/
tokens/{tokens.css,tokens.json(DTCG),figma.json}
components/{<slug>.css ×79, index.css 聚合, <slug>.html ×79}
manifest.json(含 SHA 校验和) + README.md
- .npmignore / .gitignore 更新(dist/ node_modules/ 不入库)
- npm pack 实测:115.9 KB 压缩 / 566 KB 解压 / 167 文件 / 无 site|tests 泄漏
实测发现的三个缺陷(全部修复)
1. package.json 加 "type": "module" 会让 site/dev-server.js(CJS)崩溃
—— 移除该字段,靠 .mjs 扩展名区分模块系统
2. dist 里 HTML 引用 ../tokens/colors_and_type.css 但产物是 tokens.css
—— 路径对但文件不存在,产物是坏的。重写全部引用规则
(含 index.css 的 @import 从 ./tokens/ 改为 ../tokens/)
3. 断言总数不确定:icon-contrast 是条件性推入(依赖渲染时机),
导致同一页不同次运行总数不同(960 vs 961)
—— 改为恒定输出一条(无问题=pass,有问题=skip),
断言数从 960 稳定为 1038,连跑两次完全一致
4. 顺带修 na 与 skip 重复计算(na = total - denom,但 skip 已是同一批)
—— 统一为 na = skip,算术自洽:pass+fail+skip = total
验证
- runner:passRate 100% | 79 页全通过 | 1003/1003 | N/A 35 | exit 0
- collector:完全同口径(total 1038 / pass 1003 / fail 0 / skip 35)
- dist:79/79 页面浏览器实测正常(令牌解析、无加载失败)
- 连跑两次数字完全一致(可复现)
103 lines
3.1 KiB
YAML
103 lines
3.1 KiB
YAML
name: Regression
|
||
|
||
# 每次 push / PR 自动跑回归。
|
||
# 目标:让质量不再依赖「人工记得跑」—— 这是 ROADMAP S1-P3 的核心价值。
|
||
#
|
||
# 说明:
|
||
# - playwright 是 devDependency(CI 专用工具),运行时依然零依赖。
|
||
# - dev-server 在 Ubuntu 上可正常跑(Node 脚本,跨平台)。
|
||
# - 失败时仍上传报告,便于排查。
|
||
|
||
on:
|
||
push:
|
||
branches: [main]
|
||
pull_request:
|
||
branches: [main]
|
||
workflow_dispatch:
|
||
|
||
jobs:
|
||
regression:
|
||
runs-on: ubuntu-latest
|
||
timeout-minutes: 15
|
||
|
||
steps:
|
||
- name: Checkout
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Setup Node
|
||
uses: actions/setup-node@v4
|
||
with:
|
||
node-version: '20'
|
||
|
||
- name: Cache playwright browsers
|
||
uses: actions/cache@v4
|
||
with:
|
||
path: ~/.cache/ms-playwright
|
||
key: ${{ runner.os }}-playwright-${{ hashFiles('package.json') }}
|
||
restore-keys: |
|
||
${{ runner.os }}-playwright-
|
||
|
||
- name: Install dependencies
|
||
run: npm ci || npm install
|
||
|
||
- name: Install playwright chromium
|
||
run: npx playwright install --with-deps chromium
|
||
|
||
- name: Verify zero runtime dependencies
|
||
run: |
|
||
node -e "
|
||
const p = require('./package.json');
|
||
const deps = Object.keys(p.dependencies || {});
|
||
if (deps.length) {
|
||
console.error('FAIL: 运行时依赖必须为空,实际: ' + deps.join(', '));
|
||
process.exit(1);
|
||
}
|
||
console.log('zero-dep OK');
|
||
"
|
||
|
||
- name: Start dev server
|
||
run: |
|
||
node site/dev-server.js &
|
||
# 等服务就绪(最多 15 秒)
|
||
for i in $(seq 1 30); do
|
||
if curl -sf http://127.0.0.1:3311/site/data.json > /dev/null; then
|
||
echo "server ready after ${i} attempt(s)"
|
||
exit 0
|
||
fi
|
||
sleep 0.5
|
||
done
|
||
echo "FAIL: dev-server 未在 15 秒内就绪"
|
||
exit 1
|
||
|
||
- name: Run regression
|
||
run: node tools/run-regression.mjs
|
||
|
||
- name: Upload report
|
||
uses: actions/upload-artifact@v4
|
||
if: always()
|
||
with:
|
||
name: regression-report
|
||
path: |
|
||
tests/report.json
|
||
tests/report-junit.xml
|
||
retention-days: 30
|
||
|
||
- name: Publish test summary
|
||
if: always()
|
||
run: |
|
||
if [ -f tests/report.json ]; then
|
||
node -e "
|
||
const r = require('./tests/report.json');
|
||
const a = r.assertions;
|
||
console.log('## 回归结果');
|
||
console.log('');
|
||
console.log('| 项 | 值 |');
|
||
console.log('|---|---|');
|
||
console.log('| 通过率 | ' + r.passRate + '% |');
|
||
console.log('| 断言 | ' + a.pass + '/' + (a.pass + a.fail) + ' |');
|
||
console.log('| N/A | ' + (a.na || 0) + ' |');
|
||
console.log('| 页面全通过 | ' + r.pagesAllPass + '/' + r.pages + ' |');
|
||
console.log('| 超时 | ' + ((r.timedOut || []).length) + ' |');
|
||
" >> \$GITHUB_STEP_SUMMARY
|
||
fi
|