Skip to content

Commit 27cdc15

Browse files
committed
fix: fix npm release workflow and auth configuration
- Define workflow triggers and global permissions to enable OIDC-based authentication. - Specify the NPM registry URL in the Node.js setup to authorize the publishing process. - Enable provenance and public access flags to satisfy security and publishing requirements.
1 parent c60e376 commit 27cdc15

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

.github/workflows/release.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1+
name: Release
2+
3+
# 1. 触发条件配置 (必须修复这里)
4+
on:
5+
push:
6+
branches:
7+
- main # 当推送到 main 分支时触发
8+
9+
# 2. 权限配置 (OIDC 必须)
10+
permissions:
11+
contents: read
12+
id-token: write
13+
114
jobs:
215
publish:
316
runs-on: ubuntu-latest
4-
permissions:
5-
contents: read
6-
id-token: write # OIDC 必须权限
7-
817
steps:
918
- uses: actions/checkout@v4
1019

20+
# 3. 环境配置 (修复 ENEEDAUTH 认证错误)
1121
- name: Setup Node.js
1222
uses: actions/setup-node@v4
1323
with:
1424
node-version: '20'
15-
# 👇 关键修正 1:添加这行,让 Action 自动配置 .npmrc 认证
25+
# 必须指定 registry-url,setup-node 才会生成带 Auth 的 .npmrc
1626
registry-url: 'https://registry.npmjs.org'
1727

1828
- name: Install dependencies
@@ -21,10 +31,11 @@ jobs:
2131
- name: Build project
2232
run: yarn build
2333

34+
# 4. 发布命令 (开启 Provenance)
2435
- name: Publish to NPM
2536
env:
26-
# 这一步会读取 Setup Node.js 生成的 .npmrc 配置
37+
# 读取 GitHub Secrets 中的 Token
2738
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
28-
# 👇 关键修正 2:添加 --provenance 参数
29-
# 同时添加 --access public 确保包是公开的(OIDC 目前主要支持公开包)
39+
# --provenance: 生成来源证明
40+
# --access public: 确保发布为公开包
3041
run: npm publish --provenance --access public

0 commit comments

Comments
 (0)