Skip to content

fix: optimize GitHub Actions workflows — fix slow CI (1h 48m) and broken freeze cache - #297

Merged
ShixiangWang merged 1 commit into
mainfrom
copilot/check-workflow-configurations
May 8, 2026
Merged

fix: optimize GitHub Actions workflows — fix slow CI (1h 48m) and broken freeze cache#297
ShixiangWang merged 1 commit into
mainfrom
copilot/check-workflow-configurations

Conversation

Copilot AI commented May 8, 2026

Copy link
Copy Markdown
Contributor

问题背景

Github Page workflow 中 "Pre-render all non-frozen QMD files" 步骤耗时 1h 48m,整个 CI 运行超过 2 小时。经根因分析,共发现 5 个相互关联的 workflow 配置问题。

根本原因分析

核心问题:nightly 保存的 freeze 缓存几乎为空

babelquarto::render_website() 在临时目录(withr::local_tempdir())中渲染,在那里生成 _freeze,然后只把 _site 复制回工作区,临时目录(及其 _freeze)被丢弃。因此 nightly workflow 调用 babelquarto 后,工作区 _freeze 几乎没有任何 R 文件的输出,保存的缓存无效。当 main workflow 恢复了这个无效缓存后,仍需从头重新渲染所有 60+ 个 R QMD 文件,耗时 1h 48m。

修复内容

P0:quarto-publish-update-cache.yml — 添加 Pre-render 步骤(根本修复)

在 nightly 调用 babelquarto 之前,加入与 main workflow 相同的 "Pre-render all non-frozen QMD files" 步骤,将所有 R QMD 的输出写入工作区 _freeze。这样:

  • 保存的缓存包含完整的 ~500+ 条 frozen 输出
  • babelquarto 从缓存中读取已有输出,只执行 pandoc,耗时从 ~90 min 降至 ~20 min
  • warm cache 下整体运行时间从 ~1h 48m 降至 ~20 min

P0:quarto-publish-update-cache.yml — 修复并发组名称冲突

原 nightly 并发组为 quarto-build-Github Page-refs/heads/main,与 main workflow 的并发组完全相同。main workflow 设置了 cancel-in-progress: true,导致每次有 PR 合并到 main,正在运行的 nightly 就会被取消,缓存无法保存。

修复:将 nightly 并发组改为独立名称 quarto-build-nightly-cache-update

P1:quarto-publish-update-cache.yml — 增加 timeout 到 240 分钟

首次冷启动加入 pre-render 步骤后,总耗时约 140 min(Julia setup + pre-render ~80 min + babelquarto ~20 min + 其他 ~40 min)。原 150 min timeout 已不够。

P1:quarto-publish-update-cache.yml — 统一缓存键前缀,限制缓存增长

  • 修复 restore 主键:原主键使用 github.sha(每次 commit 都变化,从不命中),改用 run_id-run_attempt 确保同一 run 的 retry 能直接命中自己的缓存
  • 统一前缀:改用 freeze-<OS>-nightly- 前缀,使 main workflow 的 restore-keys: freeze-<OS>- 能稳定匹配
  • 限制缓存增长:使用周日期键(YYYY-WNN)每周最多创建 ~7 条缓存条目,旧条目在 7 天未使用后被 GitHub 自动清除

P2:quarto-publish.yml — 排除 .zh.qmd 文件触发

自动翻译 PR 只修改 .zh.qmd 文件,但仍会触发完整 2+ 小时站点构建。在 push 触发的 paths-ignore 中加入 **/*.zh.qmd 可避免此类不必要的构建。

预期效果

场景 修复前 修复后
warm cache 构建(pre-render 步骤) ~1h 48m ~0 min(全部跳过)
babelquarto 步骤 ~12 min ~20 min(pandoc only)
整体 CI 时间 ~2h 10m ~35 min
nightly 被 push 取消 常见 不会发生
翻译 PR 触发完整构建

…ze cache

Problems fixed:
1. [P0] quarto-publish-update-cache.yml: Add pre-render all non-frozen QMDs step
   before babelquarto, so the saved freeze cache is fully populated (~500+ JSON
   entries) instead of nearly empty. Reduces warm-cache runs from ~1h48m to ~20m.
2. [P0] quarto-publish-update-cache.yml: Fix concurrency group name collision.
   The nightly had the same group as the main push workflow (which has
   cancel-in-progress:true), causing nightly builds to be cancelled on every
   push to main before they could save the cache.
3. [P1] quarto-publish-update-cache.yml: Increase timeout 150 -> 240 minutes
   to accommodate the new pre-render step on cold cache (first run ~140 min).
4. [P1] quarto-publish-update-cache.yml: Unified cache key prefix to
   freeze-<OS>-nightly- so both main and nightly workflows share the same pool.
   Use weekly date key to cap cache growth (~7 entries per week max).
   Fix restore primary key to use run_id (not sha) for stable matching.
5. [P2] quarto-publish.yml: Exclude **/*.zh.qmd from push trigger paths-ignore
   to prevent auto-translate PRs (touching only .zh.qmd) from triggering a
   full 2+ hour site rebuild.

Agent-Logs-Url: https://github.com/openbiox/Bizard/sessions/21837366-bf38-48eb-87a5-49e1981f4b5f

Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

✅ QMD Format Check

No new QMD tutorial files to check.

Automated check by the PR Review workflow.
See contribution guidance for the expected tutorial format.

@ShixiangWang
ShixiangWang marked this pull request as ready for review May 8, 2026 07:47
@ShixiangWang
ShixiangWang merged commit 8f0ce9c into main May 8, 2026
3 checks passed
@ShixiangWang
ShixiangWang deleted the copilot/check-workflow-configurations branch May 8, 2026 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants