ci(perf): 添加 Lighthouse CI 性能预算回归门槛配置
Phase 2 性能预算重构配套 CI:每次 PR 与每日凌晨 3 点对 /login 路由采样 3 次(desktop preset),断言 LCP <= 3000ms、CLS <= 0.1(error 级),FCP/TBT/INP 为 warn 级。失败时阻断合并并触发性能预算审计报告基线复核。
This commit is contained in:
71
.gitea/workflows/lighthouse.yml
Normal file
71
.gitea/workflows/lighthouse.yml
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
name: Lighthouse CI
|
||||||
|
|
||||||
|
# 性能预算回归门槛:每次 PR 与每日凌晨 3 点对关键路由采样断言。
|
||||||
|
# 失败时阻断合并,触发审计报告 docs/architecture/audit/performance-budget-audit-report.md 中基线复核。
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
schedule:
|
||||||
|
- cron: "0 3 * * *" # 每天凌晨 3 点性能采样
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lighthouse:
|
||||||
|
runs-on: CDCD
|
||||||
|
container: dockerreg.eazygame.cn/node-with-docker:22
|
||||||
|
env:
|
||||||
|
SKIP_ENV_VALIDATION: "1"
|
||||||
|
NEXT_TELEMETRY_DISABLED: "1"
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Cache npm dependencies
|
||||||
|
uses: actions/cache@v3
|
||||||
|
id: npm-cache
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
|
|
||||||
|
- name: Configure npm proxy
|
||||||
|
run: |
|
||||||
|
GATEWAY_IP=$(ip route show | grep default | awk '{print $3}')
|
||||||
|
if [ -z "$GATEWAY_IP" ]; then
|
||||||
|
GATEWAY_IP="172.17.0.1"
|
||||||
|
fi
|
||||||
|
PROXY_URL="http://$GATEWAY_IP:7890"
|
||||||
|
npm config set proxy "$PROXY_URL"
|
||||||
|
npm config set https-proxy "$PROXY_URL"
|
||||||
|
echo "http_proxy=$PROXY_URL" >> $GITHUB_ENV
|
||||||
|
echo "https_proxy=$PROXY_URL" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Start production server
|
||||||
|
run: npm run start &
|
||||||
|
env:
|
||||||
|
PORT: "3000"
|
||||||
|
|
||||||
|
- name: Wait for server
|
||||||
|
run: |
|
||||||
|
for i in {1..30}; do
|
||||||
|
curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 | grep -q "200\|307\|308" && break
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Install Lighthouse CI
|
||||||
|
run: npm install -g @lhci/cli@0.13.x
|
||||||
|
|
||||||
|
- name: Run Lighthouse CI
|
||||||
|
run: lhci autorun --config=./lighthouserc.json --collect.url=http://localhost:3000/login || true
|
||||||
|
|
||||||
|
- name: Assert performance budgets
|
||||||
|
run: lhci assert --config=./lighthouserc.json
|
||||||
35
lighthouserc.json
Normal file
35
lighthouserc.json
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"ci": {
|
||||||
|
"collect": {
|
||||||
|
"url": [
|
||||||
|
"http://localhost:3000/login"
|
||||||
|
],
|
||||||
|
"numberOfRuns": 3,
|
||||||
|
"settings": {
|
||||||
|
"preset": "desktop",
|
||||||
|
"throttling": {
|
||||||
|
"rttMs": 40,
|
||||||
|
"throughputKbps": 10240,
|
||||||
|
"cpuSlowdownMultiplier": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"assert": {
|
||||||
|
"assertions": {
|
||||||
|
"categories:performance": ["warn", { "minScore": 0.85 }],
|
||||||
|
"categories:accessibility": ["error", { "minScore": 0.9 }],
|
||||||
|
"categories:best-practices": ["warn", { "minScore": 0.85 }],
|
||||||
|
"categories:seo": ["warn", { "minScore": 0.85 }],
|
||||||
|
"largest-contentful-paint": ["error", { "maxNumericValue": 3000 }],
|
||||||
|
"cumulative-layout-shift": ["error", { "maxNumericValue": 0.1 }],
|
||||||
|
"interactive": ["warn", { "maxNumericValue": 3000 }],
|
||||||
|
"first-contentful-paint": ["warn", { "maxNumericValue": 2000 }],
|
||||||
|
"total-blocking-time": ["warn", { "maxNumericValue": 300 }]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"upload": {
|
||||||
|
"target": "filesystem",
|
||||||
|
"outputDir": "lighthouse-results"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user