Skip to content

ci: reduce pull request runner usage - #697

Merged
eetoc merged 3 commits into
mainfrom
optimize/ci-pr-runner-cost
Sep 14, 2026
Merged

eetoc merged 3 commits into
mainfrom
optimize/ci-pr-runner-cost

Conversation

@winterfx

Copy link
Copy Markdown
Collaborator

Problem

Every pull request ran the full Darwin binary matrix plus a native macOS smoke test. A recent PR spent about 4 runner minutes on those Darwin jobs, including a 3 minute macOS runner job.

Solution

  • Keep pull request binary validation on Linux amd64 and Darwin amd64.
  • Run Darwin arm64 and native macOS smoke validation on pushes to main and version tags.
  • Extend the binary CI contract test to validate both matrix outputs.

This preserves the complete platform matrix after merge while reducing pull request runner usage.

Validation

  • ./scripts/tests/test-binary-ci-contract.sh
  • git diff --check

@monkeyscan

monkeyscan Bot commented Sep 14, 2026

Copy link
Copy Markdown

PR Title: ci: reduce pull request runner usage

Commit: e095683

本次变更包含两个文件,目标是让 Darwin 构建在 PR 上只跑 amd64:\n\n1. .github/workflows/ci.yml\n - binary-matrix 新增作业输出 darwin_platforms(映射到 step 输出 darwin_json),并在 platforms 步骤中按事件写入:PR 为 ["amd64"],非 PR(main / v* tag)为 ["amd64","arm64"]。\n - binary-darwinstrategy.matrix.arch 由写死的 [amd64, arm64] 改为 fromJSON(needs.binary-matrix.outputs.darwin_platforms),与既有 binary-linux 的写法保持一致;该作业已声明 needs: binary-matrix,输出键名与 step 输出键名均一一对应。\n - binary-darwin-native 新增 if: github.event_name != 'pull_request',在 PR 上跳过 macOS 原生 smoke,进一步降低 PR 成本。\n\n2. scripts/tests/test-binary-ci-contract.sh\n - 期望值从「单输出」改为用 | 分隔的 json=...|darwin_json=...,并新增 expected=${expected//|/$'\\n'} 把分隔符还原为换行后再与 GITHUB_OUTPUT 文件内容比对;event 仍用 ${var%%|*} 提取。该多行比对逻辑经推演正确:darwin_json=[\"amd64\"] 等字面量与工作流中 echo 实际写入内容完全一致,$(<file) 去除尾随换行后与期望值相等。\n\n核对结论:工作流侧的输出写入、fromJSON 解析、作业依赖与事件分支判断均自洽,未发现功能性缺陷;binary-darwin 上仍保留的 amd64/arm64 契约断言虽然继续通过,但已不再验证矩阵接线本身,存在一处低危的测试回归防护缺口,已提交单条 finding。整体改动方向合理、风险可控。

Prompt To Fix All With AI
This is a comment left during a code review.
Repository: https://github.com/chaitin/agent-compose
Path: .github/workflows/ci.yml
Line: 245

Comment:
binary-darwin 的动态矩阵接线缺少契约测试断言,架构断言可被注释满足

本次变更把 binary-darwin 的架构列表由写死的 `arch: [amd64, arm64]` 改为 `arch: ${{ fromJSON(needs.binary-matrix.outputs.darwin_platforms) }}`,并新增 `darwin_platforms` 输出。契约测试 scripts/tests/test-binary-ci-contract.sh 虽然通过循环校验了 `darwin_json` 的写入内容,但对 binary-darwin 消费者侧仍只有两个裸字符串断言 `require_regex "$binary_darwin" 'amd64'` / `'arm64'`。而在当前 ci.yml 中,这两个字符串实际由本行上方的注释「Pull requests use amd64; main and tags use amd64 and arm64.」以及 “Inspect Darwin target” 步骤里的 `case` 分支(`amd64)` / `arm64)`)满足,不再来自矩阵定义本身。因此一旦接线写错——例如 darwin_platforms 误指向别的 step 输出、binary-darwin 忘记改用 fromJSON 而仍保留写死的 `[amd64, arm64]`、或输出 JSON 非法导致 fromJSON 失败、矩阵为空——契约测试依旧全部通过,PR 只跑 amd64 的目标以及 main/tag 上 arm64 darwin 构建会静默丢失而无法被发现。对照之下,binary-linux 在同文件中有显式的 `fromJSON(needs.binary-matrix.outputs.` 断言,darwin 侧缺少同类断言,属于本次改动引入的回归防护缺口。
---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment thread .github/workflows/ci.yml
@monkeyscan

monkeyscan Bot commented Sep 14, 2026

Copy link
Copy Markdown

PR Title: ci: reduce pull request runner usage

Commit: fd6b5f0

本次改动仅涉及 .github/workflows/images.yml 的 pull_request 触发路径过滤器(+15/-3)。

改动内容:把原先分散的 cmd/、pkg/ 归并重整,新增 buf.yaml、buf.gen.yaml、internal/、assets/;将原先宽泛的 scripts/** 收窄为 4 个具体脚本(Dockerfile 实际 COPY 的 build-agent-compose-binary.sh、with-go-toolchain.sh,以及 guest 构建相关的 build-agent-compose.sh、build-agent-compose-guest.sh);并在列表末尾追加 4 条否定模式(!/*_test.go、!/.test.ts、!**/.test.js、!/tests/),意图让纯测试改动不再触发镜像构建。

评估:否定模式均带引号且在正向模式之后,符合 GitHub Actions「最后一个匹配的模式生效」语义,能正确排除测试文件;Dockerfile 的全部构建输入(cmd/、internal/、pkg/、assets/、proto/、buf.*、go.mod/go.sum 及两个被 COPY 的脚本)也都被覆盖,新增 internal/**、buf.yaml、buf.gen.yaml 属于对既有遗漏的修复。

唯一实质问题是把 scripts/** 收窄为 4 个脚本后,本工作流自身执行/依赖的多个脚本(scripts/tests/test-image-ci-contract.sh、verify-agent-compose-image.sh、test-image-docker-e2e.sh、verify-image-manifest.sh、build-installer-assets.sh)不再纳入触发路径,PR 阶段形成 CI 校验盲区,已作为 medium 级发现提交。

Prompt To Fix All With AI
This is a comment left during a code review.
Repository: https://github.com/chaitin/agent-compose
Path: .github/workflows/images.yml
Line: 24-27

Comment:
paths 过滤器把 scripts/** 收窄为 4 个脚本,导致本工作流自身执行的校验脚本改动不再触发镜像构建

本次改动把原来的 `- scripts/**` 替换为 4 个具体脚本(build-agent-compose-binary.sh、build-agent-compose.sh、build-agent-compose-guest.sh、with-go-toolchain.sh),这一收窄只覆盖了 Dockerfile 直接 COPY 的构建脚本。但本工作流自身还在执行/依赖多个 scripts/ 下的脚本:setup 作业的 `./scripts/tests/test-image-ci-contract.sh`(第 69 行,用于校验镜像 CI 契约)、`./scripts/verify-agent-compose-image.sh`(第 142、276 行)、`./scripts/test-image-docker-e2e.sh`(第 285、292 行)、`./scripts/verify-image-manifest.sh`(第 371 行)、`./scripts/build-installer-assets.sh`(第 394 行)。这些脚本均不匹配新增的正向路径列表,因此仅修改它们的 PR 不再触发本工作流(pull_request 触发依赖 paths 过滤,而 push 触发没有 paths 过滤)。后果是这些校验/发布辅助逻辑的改动在 PR 阶段完全得不到验证,只有合并到 main 后的 push 运行时才会执行并可能直接失败,从而阻塞镜像发布流程;同时新增脚本若未被显式登记也会持续产生同类盲区。
---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment thread .github/workflows/images.yml
@monkeyscan

monkeyscan Bot commented Sep 14, 2026

Copy link
Copy Markdown

PR Title: ci: reduce pull request runner usage

Commit: 8efb1ea

本次变更范围很小(2 个文件,+7/-0),且经逐条核验后未发现需要修复的可执行问题,属于对历史 finding d78387e5 的补全。

  1. .github/workflows/images.yml(+5)——在 pull_request.paths 正向白名单中补登了 5 个脚本路径(build-installer-assets.sh、test-image-docker-e2e.sh、tests/test-image-ci-contract.sh、verify-agent-compose-image.sh、verify-image-manifest.sh)。核验方式与结论:

    • 对工作流全文做字面检索,scripts/ 的引用点共 7 处(第 74、147、281、290、297、376、399 行),新增的 5 条路径与之完全一一对应,先前"工作流自己执行的校验脚本不在触发过滤器中"的盲区已被补齐;
    • 原有 4 条(build-agent-compose-binary.sh、build-agent-compose.sh、build-agent-compose-guest.sh、with-go-toolchain.sh)仍然保留,与 Dockerfile 的 COPY scripts/... 两条引用一致;
    • 追加读取了 scripts/build-installer-assets.sh,确认它消费的 deploy/install.shdocker-compose.ymldocker-compose.kvm.yml.env.example 均由 deploy/**docker-compose*.yml.env.example 等既有条目覆盖,不存在新的间接漏配;
    • 负向规则(!**/*_test.go!**/__tests__/** 等)不会误伤新增的 .sh 脚本;契约测试 scripts/tests/test-image-ci-contract.sh 对工作流 header 只断言 docker-compose.kvm.yml 条目、registry 命名空间、- "*" 触发与禁用 ghcr.io,并不约束 scripts/* 条目集合,因此新增条目不会导致该契约测试失败。
  2. scripts/tests/test-binary-ci-contract.sh(+2)——为 binary-darwin 作业新增 fromJSON(needs.binary-matrix.outputs.darwin_platforms) 断言。对照 .github/workflows/ci.yml 确认:binary-matrix 作业确实导出 darwin_platforms: ${{ steps.platforms.outputs.darwin_json }},binary-darwin 的 arch: 正是 ${{ fromJSON(needs.binary-matrix.outputs.darwin_platforms) }},断言与实现严格一致(相比 binary-linux 的宽松写法,这里固定了 darwin 专用输出名,能防止误用 linux_platforms),不会产生假失败。

非阻塞观察(未作为 finding 提交):paths 白名单仍是手工维护的显式列表,而 test-image-ci-contract.sh 目前不会校验"工作流中引用的每个 scripts/* 是否都登记在 paths 中",同类漏配存在再次静默发生的可能;如后续加一条自检断言即可一劳永逸。整体评估:变更方向正确、实现无误,可以合入。

@eetoc
eetoc merged commit 5df391e into main Sep 14, 2026
22 checks passed
@eetoc
eetoc deleted the optimize/ci-pr-runner-cost branch September 14, 2026 10:23
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