AI

发版取了最近一次成功的验证包,那次成功不是要发的提交(中英切换)

This post is currently available in Chinese only. The original text follows.Open the Chinese page →

三人、七台电脑。1 到 3 号机跑编码代理,4、5 号机审查,6 号机做 Windows 验证,7 号机负责发版。工单写得很具体:给承运商的订单导出里,客户手机号必须脱敏,只保留后四位;完整号码不能离开仓库网。要发出去的,是已经合进 main 的那次脱敏提交。验收看起来也很清楚:6 号机验证通过,把制品上传成 windows-ok,7 号机下载这个包,确认导出文件后再发。

7 号机上的发版脚本是代理写的,读起来合理:

gh run list --workflow validate.yml --status success --limit 1
gh run download "$RUN" -n windows-ok -D /tmp/release
EXPORT=$(find /tmp/release -name export.csv | head -1)

它要的是「最近一次成功的验证包」。问题在于,「最近一次成功」说的是运行创建时间,不是你打算发的那个提交。

我在本地建了一个小仓库,两份提交。第一份 fabc6df(fabc6df82124672834f9949128f72cc05555c32d),时间是 2026-11-29 17:50(Asia/Shanghai),标题是修复导出超时,这时导出里还是完整手机号。第二份 fa1a8f0(fa1a8f01ad21982fe7608480b173814b3104166b),时间 18:05,才加上脱敏。这两份提交是我按常见的分单写法准备的夹具,并没有再开一个编码模型来生成 diff。实验室用的手机号是 13800138000 和 15555550123,只作为夹具,不是真实用户。

验证制品我做成了三次成功的 windows-ok。运行 20202 对应 fa1a8f0,在 main 上由 push 触发,创建于 18:10(Asia/Shanghai),导出已经脱敏,文件哈希是 8e69847c…。运行 10101 对应 fabc6df,在 fix/export-timeout 分支上,创建于 18:40。运行 10102 还是 fabc6df,但这是后来有人在 main 上对旧提交做的一次 workflow_dispatch,创建于 18:55。后两次制品的导出里仍然是完整手机号,哈希都是 cb6972f5…。

要发的是 fa1a8f0。release_latest.sh 不限定分支时,取到的是运行 10102。它确实成功了,只是成功的是旧提交。我在脚本末尾加了一道发版检查,专门拒绝导出里还带着完整夹具号码的文件,所以这次退出码是 1。没有这道检查,7 号机发出去的就是带 13800138000 和 15555550123 的 CSV。检查是实验室加的探针,不是那份「取最近一次成功」的脚本原来就有的。

有人会说:加上 --branch main 就够了。这次不够。运行 10102 的 workflow_dispatch 也在 main 上,只是 headSha 仍是 fabc6df。BRANCH=main 之后,脚本还是取到 10102,发版检查同样拒绝。我接着把 10102 从列表里拿掉再跑一遍:这时 --branch main 碰巧取到了 20202,脱敏文件通过了检查。这只能说明,当 main 上最新一次成功运行恰好就是你要发的那个提交时,脚本看起来是对的。它并没有检查 SHA。晚一点再对某个旧提交点一次重新运行,同一条命令就会回到未脱敏的包。

GitHub 列出工作流运行时,默认按 created_at 倒序。gh run list --status success --limit 1 吃到的就是这个顺序。同一条运行的 Re-run 通常保留原来的 created_at,不一定会排到最前;但一次新的 workflow_dispatch、一条更晚推上来的功能分支,或者一次针对旧 SHA 的手动触发,都会变成「最近的成功」。名称都叫 windows-ok 时,下载命令本身不会提醒你 SHA 已经换了。

第二条路径更安静。我这台机器上的官方 gh 是 2.103.0,它的帮助文本写得很清楚:如果只指定一个制品名称,文件会直接解到目标目录,而不是按制品名再套一层子目录;不指定时,才会按制品名分目录。帮助里还写了另一句:默认情况下,这条命令会下载最近创建的制品,要拿某一次运行的包,必须带上 run-id。我按这个语义做了夹具,没有对公开仓库做真实下载。实验室里先不带 -n 下载运行 10101,目录里留下 windows-ok/export.csv,还是未脱敏的那份;再对运行 20202 加上 -n windows-ok,新的脱敏文件摊在目录根上,变成根目录的 export.csv。此时目录里有两份 export.csv。这台机器上 find … -name export.csv 的顺序是先子目录、后根上那份。head -1 取到的是上一单留下的未脱敏文件。发版检查再次拒绝。如果 7 号机一直复用 /tmp/release,即使这次已经下载对了运行,找文件的那一行仍可能发错包。

发版取了最近一次成功的验证包,那次成功不是要发的提交

这和 6 号机贴了 windows-ok,验证过的那个提交已经不是 HEAD 不是同一层。那次是标签还在、提交已经变了。也和 6 号机验证是绿的,跑的还是上一单装进虚拟环境的包 不同:那次是验证机自己跑到了旧安装。这次验证运行都是成功的,制品也是按各自 SHA 打的;错在 6 号机和 7 号机交接时,用「最近一次成功」和「文件名叫 export.csv」代替了 SHA。

「最近一次成功」拿到的是 fabc6df 的未脱敏导出;按 SHA 固定后才发出 fa1a8f0

合理的反驳是:根本不要在 7 号机上单独下载。让构建、测试、发版放在同一次工作流里,用 needs: 把制品交给后续作业,就不需要 gh run list。这条路在「一次工作流就能发完」时更干净,能这样做就应该这样做。它解决不了另一类交接:发版发生在另一台机器、另一个工作流,或者要补发某个已经打好的标签。那时你仍然会去「下一次包」。另一种反驳是:制品证明或镜像 digest 比自己写的 provenance.json 更强。这是对的。这次实验室没有跑 GitHub 签名证明,也没有推镜像。夹具里的 provenance.json 是打包装的那次作业自己写的,单独看不够作为信任根。它能拦住的是下错目录、拿错文件;真正把运行固定到提交的,是 API 返回的 headSha 必须等于 TARGET_SHA。

release_pinned.sh 要求提供 TARGET_SHA,用 gh run list --commit 找该提交上成功的 validate.yml 运行,下载到新的 mktemp -d 目录,再核对三件事:运行的 headSha、制品里的 head_sha 和 run_id、以及 export.csv 的 sha256。最后仍然跑发版检查,因为哈希一致只说明文件没拿错,不说明行为符合工单。指向 fa1a8f0 时,脚本取到运行 20202,哈希是 8e69847c5543ea128a99cfe6f58b5f0c9d0b4df58a8c31ea1c3c8084ee7be352,检查通过。我再故意把运行 10101 的未脱敏包和目标 SHA fa1a8f0 送给闸门,闸门拒绝,因为 headSha 是 fabc6df。

发版要固定要发的那个 SHA,而不是「最近一次成功的 windows-ok」

适用边界要说清楚。如果发版作业和打包装的作业在同一次运行里,用 needs: 传递制品,这次「取最近一次成功」的错误不会出现。如果制品名本身已经包含完整 SHA,并且发版脚本拒绝任何对不上的文件名,也会少踩一截;即便如此,仍应核对 API 的 headSha,不要只信文件名。这次没有在 GitHub 上跑真实 Actions,也没有在 Windows 或 windows-latest 上下载。gh run list 和 gh run download 的行为来自 2.103.0 的官方帮助,以及按该语义实现的本地夹具;不要把夹具里的运行编号当成线上记录。未使用管理员特权。夹具提交不是现场编码模型写的。

明天就可以改自己仓库里的发版脚本。先要求明确的 TARGET_SHA,不要再写「最新一次成功」。下载必须进全新临时目录,用完删掉,不要复用 /tmp/release。gh run download 要带 run-id,不要只凭制品名取「最近一块」。发版前核对应的是这个提交,再对制品做一次行为检查——这次就是导出里不能出现完整手机号。4、5 号机如果只听到「验证绿了,包也下到了」,还应该问一句:这个包的 headSha 是不是要发的那一个。

这种脚本会写成「取最近一次成功」,往往不是因为有人想发旧包。7 号机收到的指令通常是:验证已经绿了,把那个包发上去。代理把「那个包」翻译成「最新一次成功的 windows-ok」,在只有一条成功运行时,这和要发的提交恰好重合,于是它会作为一条可复用的发版步骤留下来。三人七机的日常里,成功运行很快就会超过一条。6 号机可能对昨天已经绿过的超时修复再点一次验证,只是为了确认偶发失败不再出现;也可能是另一条还没合进 main 的功能分支刚跑完。它们都叫 windows-ok,创建时间却更晚。发版脚本不会读工单,只会读运行列表。

workflow_dispatch 在这里特别容易被忽略,因为它看起来像一次正规的 main 验证。运行 10102 的分支字段是 main,结论是 success,制品名也正确。只看分支和结论,会以为已经满足「在 main 上验证过」。缺的是:这次运行检出的是哪一个 SHA。GitHub 允许你对已经过去的提交再触发工作流,这在补跑失败任务时很有用;副作用是,列表上会出现一条又新又绿、内容却是旧树的记录。若发版以创建时间排序,补跑就会压过真正要发的那一次。

固定 SHA 的代价也很具体。7 号机不能再说「今晚绿了就发」,必须先写下要发的提交、标签或合并记录。紧急热修同样要写出热修自己的 SHA。图省事去取「最新一次成功」,恰恰是最容易发错的时候:热修分支、旧提交补跑和主分支验证会挤在同一张列表里。如果团队已经用标签发版,标签指向的 SHA 就是 TARGET_SHA,不要再从标签退回到「main 上最新的绿」。

还有一种看起来更省事的写法:gh run download -n windows-ok,连运行编号都不给。2.103.0 的帮助已经说明,默认会去取最近创建的那块制品,因为制品可能被删除或覆盖,要拿某一次运行的包就必须带 run-id。这次实验室没有拿这条默认命令去打公开仓库,但我按同一条帮助文本实现了夹具。它和 find | head 是同一类省略:把「我要的那一份」写成「名字对得上的最新一份」。

审查留言里如果只写「已从最近一次成功运行下载 windows-ok」,4、5 号机没有可核对的对象。留言至少应包含要发的 SHA、选中的运行编号,以及制品哈希。这三行都可以由发版脚本打出来,不必靠人记得去复制。缺少其中任何一项,就还不能把「包已经下达」当成发版完成。6 号机的验证评论同样应写明验证的是哪一个 SHA;只有「验证通过」四个字时,7 号机只能回去猜「最近的绿」,而这正是这次会发错包的起点。交接时把 SHA 写进留言,比事后再去列表里找「最近的绿」要便宜得多。

实际跑了什么

  • 本地 git 2.47.3、Python 3.13.5、官方 gh 2.103.0(用于阅读 gh run download / gh run list 的帮助文本)。夹具仓库两份提交:fabc6df(2026-11-29 17:50,Asia/Shanghai,未脱敏),fa1a8f0(18:05,已脱敏)。
  • 三次成功制品:运行 20202 / fa1a8f0 / 18:10(Asia/Shanghai),哈希 8e69847c…;运行 10101 / fabc6df / 18:40,哈希 cb6972f5…;运行 10102 / 仍是 fabc6df 的 workflow_dispatch / 18:55,哈希相同。
  • release_latest.sh 不限定分支,以及 BRANCH=main 时,都取到运行 10102,导出为完整手机号,发版检查拒绝。去掉 10102 后,BRANCH=main 碰巧取到 20202 并通过。
  • 复用目录中,find | head 先点到 windows-ok/export.csv(未脱敏),而不是根上那份已脱敏文件。
  • release_pinned.sh 指定 TARGET_SHA=fa1a8f0 时取到运行 20202,闸门和发版检查均通过。把运行 10101 指给闸门则被拒绝。

未跑:真实 GitHub Actions、Windows 或 windows-latest、现场编码模型、制品签名证明。可复制的脚本和夹具在 wrong-artifact-kit.tar.gz。下一步是把发版脚本改成按目标 SHA 固定运行,并用全新目录下载。

Three people, seven computers. Machines 1 to 3 run coding agents, 4 and 5 review, 6 does Windows validation, and 7 releases. The ticket was specific: in the order export sent to the carrier, customer phone numbers must be masked, last four digits only; full numbers must not leave the warehouse network. The SHA to ship is the masked commit already on main. Acceptance looks clear too: machine 6 validates, uploads an artifact named windows-ok, and machine 7 downloads that package, checks the export, and ships it.

The release script on machine 7 was written by an agent, and it reads reasonably:

gh run list --workflow validate.yml --status success --limit 1
gh run download "$RUN" -n windows-ok -D /tmp/release
EXPORT=$(find /tmp/release -name export.csv | head -1)

It asks for "the latest successful validation package". The problem is that "latest successful" refers to when the run was created, not to the commit you intended to ship.

I made a small local repository with two commits. The first, fabc6df (fabc6df82124672834f9949128f72cc05555c32d), at 2026-11-29 17:50 (Asia/Shanghai), is titled as a fix for an export timeout, and the export still contains full phone numbers. The second, fa1a8f0 (fa1a8f01ad21982fe7608480b173814b3104166b), at 18:05, adds the mask. These are fixture commits I wrote in the shape of a typical split ticket. I did not start a coding model to produce the diff. The lab phone numbers are 13800138000 and 15555550123. They are fixtures, not real people.

I built three successful windows-ok artifacts. Run 20202 corresponds to fa1a8f0, triggered by a push on main, created at 18:10 (Asia/Shanghai); the export is masked, and the file hash is 8e69847c…. Run 10101 corresponds to fabc6df, on the fix/export-timeout branch, created at 18:40. Run 10102 is still fabc6df, but it is a later workflow_dispatch of that older commit on main, created at 18:55. The last two artifacts still contain the full numbers, and both hash to cb6972f5….

The SHA to ship is fa1a8f0. With no branch filter, release_latest.sh picked run 10102. That run really did succeed; what succeeded was the old commit. I added a ship check at the end of the script that refuses an export still carrying the full fixture numbers, so the exit code was 1. Without that check, machine 7 would have shipped a CSV containing 13800138000 and 15555550123. The check is a probe I added in the lab. It was not part of the original "take the latest success" script.

A reasonable response is: just add --branch main. That was not enough here. The workflow_dispatch for run 10102 was also on main; only its headSha was still fabc6df. With BRANCH=main, the script still picked 10102, and the ship check refused again. I then dropped 10102 from the list and reran: --branch main happened to pick 20202, and the masked file passed. That only shows that the script looks right when the latest successful run on main happens to be the commit you wanted. It never checked the SHA. Trigger the older commit once more, a little later, and the same command goes back to the unmasked package.

GitHub lists workflow runs by created_at descending by default. gh run list --status success --limit 1 consumes that order. Re-running the same run usually keeps the original created_at, so it may not sort first; a new workflow_dispatch, a feature branch that finishes later, or a manual trigger of an old SHA, will become "the latest success". When every artifact is named windows-ok, the download command itself will not tell you the SHA has changed.

The second path is quieter. The official gh on this machine is 2.103.0. Its help text is explicit: if only a single artifact name is specified, the files are extracted into the target directory, with no extra directory named after the artifact; without that, each artifact gets its own subdirectory. The help also says that by default the command downloads the latest artifact created, and that a run-id is required to take an artifact from a specific run. I implemented the fixture from that wording. I did not perform a live download from a public repository. In the lab I first downloaded run 10101 without -n, which left windows-ok/export.csv, still unmasked; then I downloaded run 20202 with -n windows-ok, and the new masked file landed at the directory root as export.csv. There were now two files named export.csv. On this machine, find … -name export.csv listed the subdirectory first, then the one at the root. head -1 selected last job's unmasked file. The ship check refused again. If machine 7 keeps reusing /tmp/release, even a download of the right run can still ship the wrong file at the find line.

The release script took the latest successful artifact, which was not the commit we meant to ship

This is not the same layer as Machine 6 pasted windows-ok, but the commit it validated is no longer HEAD. That post was about a label that outlived the commit. It is also not the same as Validation went green on machine 6, but it still imported the last job's install: that was the validation machine running against a stale install. This time every validation run succeeded, and each artifact was built from its own SHA. The mistake was in the handoff from machine 6 to machine 7, where "latest successful" and "the file is named export.csv" were used in place of the SHA.

Latest success selected the unmasked export from fabc6df; pinning the SHA shipped fa1a8f0

A fair objection is: do not download on machine 7 at all. Keep the build, the tests, and the release in the same workflow, and pass the artifact with needs:, and you will not need gh run list. That path is cleaner when one workflow can finish the release, and you should take it when you can. It does not cover the other handoff: the release runs on another machine, or in another workflow, or you need to republish a tag that has already been built. Then you will still "download a package". Another objection is that artifact attestations or an image digest are stronger than a provenance.json you wrote yourself. That is true. This lab did not run GitHub attestations and did not push an image. The provenance.json in the fixture is written by the same job that built the zip, and is not a root of trust on its own. It can catch a wrong directory or a swapped file. What actually pins the run to the commit is that the headSha returned by the API must equal TARGET_SHA.

release_pinned.sh requires TARGET_SHA, uses gh run list --commit to find a successful validate.yml run for that commit, downloads into a fresh mktemp -d, and then checks three things: the run's headSha, the head_sha and run_id inside the artifact, and the sha256 of export.csv. It still runs the ship check afterwards, because a matching hash only means you have the right file, not that the behavior matches the ticket. Pointed at fa1a8f0, the script selected run 20202, the hash was 8e69847c5543ea128a99cfe6f58b5f0c9d0b4df58a8c31ea1c3c8084ee7be352, and the check passed. I then deliberately gave the gate the unmasked package from run 10101 with target SHA fa1a8f0; the gate refused, because the headSha was fabc6df.

The release must pin the SHA you intend to ship, not the latest successful windows-ok

The limits should be stated clearly. If the release job and the build job run in the same workflow and pass the artifact with needs:, the "latest successful" mistake in this post does not appear. If the artifact name itself contains the full SHA, and the release script refuses any name that does not match, you avoid part of the path; even then, you should still check the API headSha, and not trust the file name alone. This lab did not run real GitHub Actions, and did not download on Windows or windows-latest. The behavior of gh run list and gh run download comes from the official help text of 2.103.0, and from a local fixture that follows that wording. Do not treat the fixture run ids as records from a live repository. Admin privileges were not used. The fixture commits were not written by a live coding model.

You can change the release script in your own repository tomorrow. Require an explicit TARGET_SHA. Stop writing "the latest success". Downloads must go into a fresh temporary directory, which is deleted afterwards; do not reuse /tmp/release. gh run download needs a run-id; do not take "the latest one with this name" by artifact name alone. Before shipping, confirm that this is the intended commit, then run a behavior check on the artifact — in this case, that the export contains no full phone numbers.

A script ends up saying "take the latest success" usually not because someone wanted to ship an old package. The instruction machine 7 receives is often: validation is green, ship that package. The agent translates "that package" into "the latest successful windows-ok". When there is only one successful run, that coincides with the intended commit, and the line stays around as a reusable release step. In a three-person, seven-machine day, there will soon be more than one successful run. Machine 6 may re-validate a timeout fix that was already green yesterday, only to confirm that a flake is gone; or another feature branch that has not landed on main may just have finished. Both artifacts are named windows-ok, and both are newer. The release script does not read the ticket. It reads the run list.

workflow_dispatch is especially easy to miss here, because it looks like a regular validation on main. Run 10102 has main in the branch field, a successful conclusion, and the right artifact name. Looking only at the branch and the conclusion, you would think "validated on main" was already satisfied. What is missing is: which SHA did this run check out? GitHub lets you trigger a workflow against a commit that has already passed, which is useful when rerunning a failed job; the side effect is a row that is both new and green, but whose tree is old. If the release sorts by creation time, the rerun will outrank the run you actually meant to ship.

Pinning the SHA has a concrete cost. Machine 7 can no longer say "ship whatever is green tonight". It has to write down the commit, the tag, or the merge record first. An emergency hotfix still has to name its own SHA. Taking "the latest success" to save time is exactly when the wrong package is most likely to go out: a hotfix branch, a rerun of an old commit, and a main-branch validation will share the same list. If the team already releases from tags, the SHA the tag points at is TARGET_SHA. Do not fall back from the tag to "the latest green on main".

There is an even shorter form: gh run download -n windows-ok, with no run id at all. The 2.103.0 help already says the default is to download the latest artifact created, and that a run-id is required to take a package from a specific run, because artifacts can be deleted or overwritten. This lab did not run that default command against a public repository, but the fixture follows the same help text. It is the same kind of omission as find | head: writing "the one I want" as "the latest one whose name matches".

If a review comment only says "downloaded windows-ok from the latest successful run", machines 4 and 5 have nothing to check. The comment should at least include the SHA to ship, the run id that was selected, and the artifact hash. The release script can print all three; nobody has to remember to copy them by hand. If any one of them is missing, "the package has been downloaded" is not yet a completed release. The validation comment from machine 6 should also name the SHA that was validated; if it only says "validation passed", machine 7 can only go back and guess "the latest green", which is exactly where this wrong release starts. Writing the SHA into the handoff comment is much cheaper than looking for "the latest green" in the list afterwards.

What was actually run

  • Locally: git 2.47.3, Python 3.13.5, official gh 2.103.0 (used to read the help text for gh run download and gh run list). Two fixture commits: fabc6df (2026-11-29 17:50, Asia/Shanghai, unmasked) and fa1a8f0 (18:05, masked).
  • Three successful artifacts: run 20202 / fa1a8f0 / 18:10 (Asia/Shanghai), hash 8e69847c…; run 10101 / fabc6df / 18:40, hash cb6972f5…; run 10102 / a workflow_dispatch of the same fabc6df / 18:55, same hash.
  • release_latest.sh with no branch filter, and with BRANCH=main, both selected run 10102, with full phone numbers in the export, and the ship check refused. After dropping 10102, BRANCH=main happened to select 20202 and passed.
  • In a reused directory, find | head hit windows-ok/export.csv (unmasked) first, not the masked file at the root.
  • release_pinned.sh with TARGET_SHA=fa1a8f0 selected run 20202; the gate and the ship check both passed. Pointing the gate at run 10101 was refused.

Not run: live GitHub Actions, Windows or windows-latest, a live coding model, or artifact attestations. The copyable scripts and fixtures are in wrong-artifact-kit.tar.gz. The next step is to make the release script pin the run to the target SHA, and to download into a fresh directory.