Skip to content

fix(ci): 跨仓库客户端改名——github-script 本来就声明了 octokit(修 #4553 引入的红检查) - #4573

Merged
os-zhuang merged 2 commits into
mainfrom
claude/fix-cross-repo-closer-octokit
Aug 2, 2026
Merged

fix(ci): 跨仓库客户端改名——github-script 本来就声明了 octokit(修 #4553 引入的红检查)#4573
os-zhuang merged 2 commits into
mainfrom
claude/fix-cross-repo-closer-octokit

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

紧急度说明:#4553 合入后,当前 main 上每一个 PR 合并都会挂一个红检查。 本 PR 修掉它。

失败

actions/github-script 会往脚本作用域注入一个 octokit 绑定,而 #4553 里我写了 const octokit = require('@actions/github').getOctokit(token)。于是一行业务逻辑都没执行就崩了:

SyntaxError: Identifier 'octokit' has already been declared
    at new AsyncFunction (<anonymous>)
    at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v9/dist/index.js:64949:16)
##[error]Unhandled error: SyntaxError: Identifier 'octokit' has already been declared

(run 30738782877,run_number: 1 —— 该工作流有史以来的第一次运行,发生在 #4553 自身的合并事件上。)

改法:把那个客户端改名为 crossRepo。注释保留原意——github 绑定的是 GITHUB_TOKEN,对本仓库之外没有写权限,所以才需要第二个客户端。

合并前的验证为什么没抓到它——这一点比修复本身值得记

#4553 合并前我做过 node --check,而且它报告通过。用的包装是:

module.exports = async ({github, context, core, require}) => { …脚本… }

一个不声明某个注入标识符的包装,不可能看见与它的命名冲突。 检查回答的是一个比运行时更窄的问题,却被当成了同一个问题的答案——所以它给出的绿灯是真实的,只是无关。

本 PR 把包装补成 github-script 实际注入的全集:

module.exports = async ({github, context, core, exec, glob, io, fetch,
                         require, octokit, __original_require__}) => {  }

并做了反证:旧写法(const octokit = …)在新包装下确实报 SyntaxError,新写法通过。也就是说这道检查现在对这类缺陷有判别力,而不只是能通过。

与本仓库正在修的一类问题同形

#4553 的正文里我写过「本 PR 自身合并即是它的第一次真实执行,这本身就是可观察的验收信号」,后来又发更正评论说它多半不会在自己的合并上触发。那条更正也是错的——它确实触发了(base`` 分支在 closed 事件发出时已含该文件)。

一句原始声明加一句更正,两条都不准,而真实结果是第三种:触发了,然后崩了。这正是 #4550 记录的形状——静态检查通过被当成了运行时正确,而两者回答的不是同一个问题。这次的实例已经写进 #4550 的语境里。

验证状态(如实)

状态
YAML 解析
脚本语法(含注入标识符全集的包装)
旧写法在同一检查下报错(反证)
关键字正则样本 ✅(#4553 已验,未改动该部分)
端到端真实合并 仍未实测 —— 本 PR 合并即是下一次真实运行,届时应当因本 PR 正文不含跨仓库关键字而记录 No cross-repository closing keywords in this PR body. 并成功退出。这是可核验的预期,不是验收结论;若它再次失败,请以 Actions 日志为准。

配套修复已推到 objectui 的 #3179(尚未合并,在合并前修掉,那边不会经历这一轮红)。


Generated by Claude Code

…s `octokit`

`actions/github-script` injects an `octokit` binding, so `const octokit = ...`
aborts the run with a SyntaxError before any logic executes. Caught on #4553's
own merge, the first time the workflow ever ran; until this lands every merged
PR carries one red check.

The pre-merge `node --check` missed it because the test wrapper declared only
{github, context, core, require} — a wrapper that omits an injected identifier
cannot see a collision with it. The wrapper now carries the full set.
@vercel

vercel Bot commented Aug 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
objectstack Ignored Ignored Aug 2, 2026 8:23am

Request Review

Without this the job returns early whenever a PR body carries no cross-repo
reference — which is most PRs — so a repository that has the secret and one
that does not produce byte-identical logs. Whether the credential is
provisioned stays unanswerable until a cross-repo reference happens to show
up, possibly days later.

Presence only; the value is never read into the log.
@os-zhuang
os-zhuang marked this pull request as ready for review August 2, 2026 08:31
@os-zhuang
os-zhuang added this pull request to the merge queue Aug 2, 2026
Merged via the queue into main with commit dafb390 Aug 2, 2026
17 checks passed
@os-zhuang
os-zhuang deleted the claude/fix-cross-repo-closer-octokit branch August 2, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/cd documentation Improvements or additions to documentation size/s tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants