Skip to content

ci(publish): npm publish 失败时自动重试,已发布的版本视为成功 - #86

Merged
qiansc merged 1 commit into
mainfrom
ci/publish-retry
Oct 26, 2026
Merged

qiansc merged 1 commit into
mainfrom
ci/publish-retry

Conversation

@qiansc

@qiansc qiansc commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Summary

发布工作流对单个包的 npm publish 失败自动重试,并在 registry 已出现该版本时视为成功。

Compatibility

None. 只改 .github/workflows/publish.yml 的发布步骤;包内容、版本与发布顺序不变。

Verification

见下方「自测情况」。

Checklist

  • bun run verify:full passes.(未改代码)
  • Lifecycle changes include route and recovery tests.(不涉及)
  • Published package metadata and local pack behavior were checked when affected.(不涉及)
  • English and Simplified Chinese user documentation remain behaviorally equivalent.(未改文档)
  • Runtime code remains compatible with Node.js 20+.(不涉及)
  • No generated output, secrets, private sources, or local workspaces are included.

背景

v0.7.86 发布时,@c4a/context-cli 的 provenance 签名遇到 Sigstore transparency log 的临时 409("an equivalent entry already exists"),整个发布任务失败,需要人工 re-run。工作流已会跳过已发布的包,但单个包没有重试。

改动

  • 每个包最多尝试 3 次,间隔 30 秒,输出 ::warning:: 注明第几次。
  • 每次失败后先查询 registry:若该版本已存在(失败的那次实际已发布),记录后继续下一个包,不再重复发布。
  • 3 次都失败时输出 ::error:: 并以非零退出,行为与原来一致。

未纳入:去掉 markdown-it-cjk-friendly 自动安装的 peer markdown-it@15。唯一的办法是把插件源码复制进仓库,会失去由上游维护规则的好处;多装的这个包本身无害。

风险

重试只在发布失败时发生;最坏情况多等 60 秒。不会重复发布同一版本(npm 也会拒绝)。

向后兼容

无影响。

自测情况

  • publish.yml YAML 解析通过;发布步骤脚本 bash -n 通过。
  • 用假的 npm 跑发布循环的三种情况:先失败后成功(尝试 2 次,退出 0);失败但已发布(尝试 1 次,识别为已发布,退出 0);一直失败(尝试 3 次,退出 1)。

🤖 Generated with Claude Code

Provenance signing can fail transiently, as the v0.7.86 release did on
@c4a/context-cli with a Sigstore transparency-log 409. Retry each package
up to three times, 30 seconds apart, and stop as soon as the registry
shows the version, because a failed attempt may still have published it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@qiansc
qiansc merged commit 5885055 into main Oct 26, 2026
2 checks passed
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.

1 participant