Skip to content

Commit ca0666e

Browse files
committed
ci(publish): configure npm Trusted Publishers authentication
Configure npm Trusted Publishers authentication by setting registry-url and unsetting NODE_AUTH_TOKEN to force OIDC authentication in publish workflow, replacing the previous approach that relied on npm CLI handling OIDC auth implicitly. // 配置 npm 可信发布者身份验证,通过设置 registry-url // 并取消设置 NODE_AUTH_TOKEN 以在发布工作流程中强制使用 OIDC 身份验证, // 替换了之前依赖 npm CLI 隐式处理 OIDC 身份验证的方法。 Change-Id: I90b04ec15b767d1f16604e291c998da98d9d6514 Signed-off-by: OhYee <[email protected]>
1 parent 3669516 commit ca0666e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

.github/workflows/publish.yaml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,13 @@ jobs:
7070
uses: actions/setup-node@v4
7171
with:
7272
node-version: '20'
73-
# Note: Do NOT set registry-url here, let npm CLI handle OIDC auth
73+
registry-url: 'https://registry.npmjs.org'
7474

7575
- name: Upgrade npm for Trusted Publishers
7676
run: |
7777
npm --version
7878
npm install -g npm@latest
7979
npm --version
80-
# Verify npm is configured correctly for Trusted Publishers
81-
npm config list
8280
8381
- name: Determine test version
8482
id: version
@@ -127,6 +125,10 @@ jobs:
127125
VERSION="${{ steps.version.outputs.VERSION }}"
128126
echo "Publishing ${PACKAGE_NAME}@${VERSION} with tag=test"
129127
npm publish --tag test --access public
128+
env:
129+
# Unset NODE_AUTH_TOKEN to force npm to use OIDC authentication
130+
# Organization may have NPM_TOKEN configured, but we want Trusted Publishers
131+
NODE_AUTH_TOKEN: ''
130132

131133
- name: Summary
132134
run: |
@@ -165,15 +167,13 @@ jobs:
165167
uses: actions/setup-node@v4
166168
with:
167169
node-version: '20'
168-
# Note: Do NOT set registry-url here, let npm CLI handle OIDC auth
170+
registry-url: 'https://registry.npmjs.org'
169171

170172
- name: Upgrade npm for Trusted Publishers
171173
run: |
172174
npm --version
173175
npm install -g npm@latest
174176
npm --version
175-
# Verify npm is configured correctly for Trusted Publishers
176-
npm config list
177177
178178
- name: Determine version
179179
id: config
@@ -267,6 +267,10 @@ jobs:
267267
VERSION="${{ steps.config.outputs.VERSION }}"
268268
echo "Publishing ${PACKAGE_NAME}@${VERSION} with tag=latest"
269269
npm publish --tag latest --access public
270+
env:
271+
# Unset NODE_AUTH_TOKEN to force npm to use OIDC authentication
272+
# Organization may have NPM_TOKEN configured, but we want Trusted Publishers
273+
NODE_AUTH_TOKEN: ''
270274

271275
- name: Summary
272276
run: |
@@ -302,15 +306,13 @@ jobs:
302306
uses: actions/setup-node@v4
303307
with:
304308
node-version: '20'
305-
# Note: Do NOT set registry-url here, let npm CLI handle OIDC auth
309+
registry-url: 'https://registry.npmjs.org'
306310

307311
- name: Upgrade npm for Trusted Publishers
308312
run: |
309313
npm --version
310314
npm install -g npm@latest
311315
npm --version
312-
# Verify npm is configured correctly for Trusted Publishers
313-
npm config list
314316
315317
- name: Determine version
316318
id: version
@@ -355,6 +357,10 @@ jobs:
355357
VERSION="${{ steps.version.outputs.VERSION }}"
356358
echo "Publishing ${PACKAGE_NAME}@${VERSION} with tag=test"
357359
npm publish --tag test --access public
360+
env:
361+
# Unset NODE_AUTH_TOKEN to force npm to use OIDC authentication
362+
# Organization may have NPM_TOKEN configured, but we want Trusted Publishers
363+
NODE_AUTH_TOKEN: ''
358364

359365
- name: Summary
360366
run: |

0 commit comments

Comments
 (0)