Skip to content

Commit 69b21ae

Browse files
thinkthinkingclaude
andcommitted
ci: npm 发布改用 OIDC Trusted Publishing(无需 token)
弃用 NPM_TOKEN,改用 OIDC:每次发布动态生成短期凭证, GitHub 上无需存任何长期密钥,永不过期、无轮换负担。 - 加 id-token: write 权限让 job 生成 OIDC token - 用 Node 24(自带 npm v11 ≥ 11.5.1,满足 OIDC 要求) - 刻意不设 auth token 环境变量(设空串会让 npm 误用空 token) - provenance 自动生成 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 890a3c9 commit 69b21ae

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

.github/workflows/release.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
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
@@ -79,8 +84,10 @@ jobs:
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 }}

0 commit comments

Comments
 (0)