From ad118b470d55731ad741b5d406b8d4cae664cc4b Mon Sep 17 00:00:00 2001 From: zqlit Date: Thu, 1 Oct 2026 11:42:43 +0800 Subject: [PATCH] =?UTF-8?q?perf(ci):=20Gitea=20=E7=8E=AF=E5=A2=83=E8=B7=B3?= =?UTF-8?q?=E8=BF=87=E6=97=A0=E6=95=88=E7=BC=93=E5=AD=98=EF=BC=8C=E6=B6=88?= =?UTF-8?q?=E9=99=A4=E6=AF=8F=E6=AC=A1=E7=BA=A6=209=20=E5=88=86=E9=92=9F?= =?UTF-8?q?=E7=A9=BA=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:/opt/gitea/runner/config.yaml 中 container.network=gitea_default (job 容器落在 172.20.x),但 runner 容器自身只挂在 bridge 网络 (172.17.0.2),其提供的缓存服务 172.17.0.2:44869 跨 bridge 网段不可达。 实测证据: - runner 容器内 wget http://127.0.0.1:44869/ -> HTTP 404(服务活着) - gitea 容器 wget http://172.17.0.2:44869/ -> download timed out - 构建日志:Setup Node restore 死等 278s(01:07:17 -> 01:11:55 ETIMEDOUT) Post Setup Node save 死等 288s(01:14:54 -> 01:19:42 ETIMEDOUT) Cache Hugo resources restore 亦超时 合计每次构建约 10 分钟纯浪费,且缓存从未真正命中或保存成功过。 改动: - Setup Node 的 cache 改为按 github.server_url 条件启用;Gitea 上 表达式求值为空串,setup-node 自动跳过缓存 - Cache Hugo resources 步骤加 if 条件,Gitea 上不执行(避免 restore+save 双超时) - npm ci 增加 --no-audit --no-fund - step summary 在 Gitea 上如实显示"已跳过",不再误报"未命中" 无副作用:npm ci 实测 68s 本就是在无缓存状态下跑的(restore 从未成功), 去掉缓存不会使其变慢;GitHub 侧行为完全不变。 --- .github/workflows/deploy.yml | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index aff03321..85f91132 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -148,12 +148,17 @@ jobs: uses: actions/setup-node@v4 with: node-version: '22' - cache: 'npm' + # Gitea 的 runner 缓存服务与 job 容器跨 bridge 网络不可达, + # 每次 restore/save 各死等约 4 分半后 ETIMEDOUT(纯浪费约 9 分钟), + # 因此仅在 GitHub 上启用缓存;Gitea 上传空值让 setup-node 跳过缓存。 + cache: ${{ github.server_url == 'https://github.com' && 'npm' || '' }} - name: Install Node.js dependencies - run: npm ci + run: npm ci --no-audit --no-fund - name: Cache Hugo resources + # 同 Setup Node:Gitea 环境缓存服务不可达,跳过以免每次白等 + if: github.server_url == 'https://github.com' uses: actions/cache@v4 id: hugo-cache with: @@ -362,7 +367,11 @@ jobs: echo "- **文件总数**: ${{ steps.stats.outputs.file_count }}" >> $GITHUB_STEP_SUMMARY echo "- **总大小**: ${{ steps.stats.outputs.total_size }}" >> $GITHUB_STEP_SUMMARY echo "- **构建哈希**: ${{ steps.hash.outputs.build_hash }}" >> $GITHUB_STEP_SUMMARY - echo "- **Hugo 缓存**: ${{ steps.hugo-cache.outputs.cache-hit == 'true' && '✅ 命中' || '🔄 未命中' }}" >> $GITHUB_STEP_SUMMARY + if [ "${{ github.server_url }}" = "https://github.com" ]; then + echo "- **Hugo 缓存**: ${{ steps.hugo-cache.outputs.cache-hit == 'true' && '✅ 命中' || '🔄 未命中' }}" >> $GITHUB_STEP_SUMMARY + else + echo "- **Hugo 缓存**: ⏭️ 已跳过 (Gitea 缓存服务跨网段不可达)" >> $GITHUB_STEP_SUMMARY + fi # ============================================================ # Job 3: Deploy to EdgeOne Pages (并行) @@ -564,10 +573,13 @@ jobs: uses: actions/setup-node@v4 with: node-version: '22' - cache: 'npm' + # Gitea 的 runner 缓存服务与 job 容器跨 bridge 网络不可达, + # 每次 restore/save 各死等约 4 分半后 ETIMEDOUT(纯浪费约 9 分钟), + # 因此仅在 GitHub 上启用缓存;Gitea 上传空值让 setup-node 跳过缓存。 + cache: ${{ github.server_url == 'https://github.com' && 'npm' || '' }} - name: Install Node.js dependencies - run: npm ci + run: npm ci --no-audit --no-fund - name: Determine deployment status id: deploy-status