perf(ci): Gitea 环境跳过无效缓存,消除每次约 9 分钟空等
Deploy to Production / pre-check (push) Successful in 54s
Deploy to Production / build (push) Successful in 9m8s
Deploy to Production / deploy-edgeone (push) Successful in 5m29s
Deploy to Production / deploy-upyun (push) Successful in 6s
Deploy to Production / finalize (push) Successful in 4m17s
Deploy to Production / notify-failure (push) Skipped

根因:/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 侧行为完全不变。
This commit is contained in:
zqlit committed 2026-10-01 11:42:43 +08:00
1 parent 6838934fa5
commit ad118b470d
1 file changed
+17 -5
+17 -5
View File
@@ -148,12 +148,17 @@ jobs:
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: '22' 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 - name: Install Node.js dependencies
run: npm ci run: npm ci --no-audit --no-fund
- name: Cache Hugo resources - name: Cache Hugo resources
# 同 Setup Node:Gitea 环境缓存服务不可达,跳过以免每次白等
if: github.server_url == 'https://github.com'
uses: actions/cache@v4 uses: actions/cache@v4
id: hugo-cache id: hugo-cache
with: with:
@@ -362,7 +367,11 @@ jobs:
echo "- **文件总数**: ${{ steps.stats.outputs.file_count }}" >> $GITHUB_STEP_SUMMARY echo "- **文件总数**: ${{ steps.stats.outputs.file_count }}" >> $GITHUB_STEP_SUMMARY
echo "- **总大小**: ${{ steps.stats.outputs.total_size }}" >> $GITHUB_STEP_SUMMARY echo "- **总大小**: ${{ steps.stats.outputs.total_size }}" >> $GITHUB_STEP_SUMMARY
echo "- **构建哈希**: ${{ steps.hash.outputs.build_hash }}" >> $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 (并行) # Job 3: Deploy to EdgeOne Pages (并行)
@@ -564,10 +573,13 @@ jobs:
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: '22' 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 - name: Install Node.js dependencies
run: npm ci run: npm ci --no-audit --no-fund
- name: Determine deployment status - name: Determine deployment status
id: deploy-status id: deploy-status