From 1a34d1f14e145ba05856897dd72af7d7c0110de3 Mon Sep 17 00:00:00 2001 From: SpecialX <47072643+wangxiner55@users.noreply.github.com> Date: Mon, 6 Jul 2026 15:58:49 +0800 Subject: [PATCH] =?UTF-8?q?ci(perf):=20=E6=B7=BB=E5=8A=A0=20Lighthouse=20C?= =?UTF-8?q?I=20=E6=80=A7=E8=83=BD=E9=A2=84=E7=AE=97=E5=9B=9E=E5=BD=92?= =?UTF-8?q?=E9=97=A8=E6=A7=9B=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase 2 性能预算重构配套 CI:每次 PR 与每日凌晨 3 点对 /login 路由采样 3 次(desktop preset),断言 LCP <= 3000ms、CLS <= 0.1(error 级),FCP/TBT/INP 为 warn 级。失败时阻断合并并触发性能预算审计报告基线复核。 --- .gitea/workflows/lighthouse.yml | 71 +++++++++++++++++++++++++++++++++ lighthouserc.json | 35 ++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 .gitea/workflows/lighthouse.yml create mode 100644 lighthouserc.json diff --git a/.gitea/workflows/lighthouse.yml b/.gitea/workflows/lighthouse.yml new file mode 100644 index 0000000..85e63d6 --- /dev/null +++ b/.gitea/workflows/lighthouse.yml @@ -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 diff --git a/lighthouserc.json b/lighthouserc.json new file mode 100644 index 0000000..2eafb87 --- /dev/null +++ b/lighthouserc.json @@ -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" + } + } +}