发布改由 main 上的版本号变化触发,而不是打 tag - #27
Open
forrestlinfeng wants to merge 1 commit into
Open
forrestlinfeng wants to merge 1 commit into
forrestlinfeng wants to merge 1 commit into
Conversation
原来要先打一个 v* tag 才发布,而 tag 可以被移动,这个 job 又持有 npm token。改成 push 到 main 时比对 package.json 的版本是否已在 npm 上: 不在就发,在就跳过。发布意图因此等同于"改版本号"这一件事,不需要再 记得补一个 tag。 token 收进 npm-publish 这个 environment,与本仓库其他 workflow 隔离, 并写进一个临时的 userconfig 而不是全局 npmrc。provenance 关掉——npm 拒绝来自私有源仓库的 provenance。发布后带重试地回查一次,确认包真的 能从 registry 解析出来,而不是只看 publish 的退出码。 并发组 npm-publish 且不取消进行中的任务:两次连续推送不会让第二次把 第一次的发布腰斩。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改了什么
.github/workflows/publish.yml的触发条件从push: tags: ['v*']改成push: branches: [main]。每次推到 main 时比对package.json的版本是否已在 npm 上——不在就发布,在就跳过。README 的两处说明同步更新。为什么
具体做法
npm-publishenvironment,与本仓库其他 workflow 隔离mktemp出来的临时 userconfig(chmod 600+trap清理),不污染全局 npmrcnpm view,确认包真的能从 registry 解析,而不是只看 publish 的退出码group: npm-publish且cancel-in-progress: false,两次连续推送不会让第二次把第一次的发布腰斩workflow_dispatch仍然跑完除发布外的所有步骤,可以从任意分支彩排Reviewer 需要知道的
这条 PR 合入后,行为是"main 上出现一个 npm 上没有的版本号就自动发布到公共 npm"。 这是不可撤回的对外动作,而且门槛从"有人刻意打 tag"降到了"有人改了
package.json的 version 字段"。如果希望保留一道人工闸门,可以给npm-publishenvironment 配上 required reviewers——workflow 本身不需要再改。需要在仓库里配置好
npm-publishenvironment 及其NPM_TOKENsecret,否则发布步骤会在${NPM_TOKEN:?...}处明确报错退出,而不是静默跳过。当前
package.json是0.1.0,npm 上不存在,所以合入即会触发首次发布。验证
npm test90 passed / 0 failed。workflow YAML 解析通过,触发条件与 job 结构如上。发布路径本身没法在 PR 里演练——需要 environment 和 token 就位后,用workflow_dispatch跑一次彩排(它会执行除 publish 外的每一步)。说明
这两个文件的改动是在本次会话的工作区里发现的未提交内容,不是我写的;我按
/create-pr的要求把它们提交成了独立分支并开了这条 PR。本次会话我自己的插件改动走的是另一条线,已作为 #26 合入。🤖 Generated with Claude Code