File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4343 env :
4444 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4545
46- # 第二步:发布 npm 分发壳。
46+ # 第二步:发布 npm 分发壳,用 OIDC Trusted Publishing(无需任何 token) 。
4747 # - tag push:等 goreleaser 成功后再发(postinstall 要从 Release 下载二进制)。
4848 # - 手动触发:直接发(Release 已存在)。
4949 npm-publish :
@@ -54,13 +54,18 @@ jobs:
5454 always() &&
5555 (github.event_name == 'workflow_dispatch' || needs.goreleaser.result == 'success')
5656 runs-on : ubuntu-latest
57+ permissions :
58+ contents : read
59+ # OIDC 关键权限:允许本 job 生成 OIDC token 向 npm 认证。
60+ id-token : write
5761 steps :
5862 - uses : actions/checkout@v6
5963
6064 - name : Set up Node
6165 uses : actions/setup-node@v6
6266 with :
63- node-version : " 22"
67+ # Node 24 自带 npm v11(≥ 11.5.1),满足 OIDC Trusted Publishing 要求。
68+ node-version : " 24"
6469 registry-url : " https://registry.npmjs.org"
6570
6671 - name : Resolve version
7984 working-directory : npm/package
8085 run : npm version "${{ steps.ver.outputs.version }}" --no-git-tag-version --allow-same-version
8186
82- - name : Publish to npm
87+ - name : Publish to npm (OIDC)
8388 working-directory : npm/package
89+ # 关键:本步骤刻意不设置任何 npm auth token 环境变量。
90+ # 哪怕设成空字符串,npm 也会误用空 token 而非走 OIDC;
91+ # 只有完全不设置时,npm 才会自动检测并使用 OIDC 认证。
92+ # provenance 在 OIDC 下自动生成,无需 --provenance。
8493 run : npm publish --access public
85- env :
86- NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
You can’t perform that action at this time.
0 commit comments