Skip to content

Commit be934c7

Browse files
committed
ci(npm-publish): rework auth using actions/setup-node
1 parent bd490c0 commit be934c7

File tree

1 file changed

+11
-6
lines changed
  • .github/workflows/actions/publish-npm-package

1 file changed

+11
-6
lines changed

.github/workflows/actions/publish-npm-package/action.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ inputs:
2323
runs:
2424
using: "composite"
2525
steps:
26+
- uses: actions/setup-node@v6
27+
with:
28+
node-version: "lts/*"
29+
package-manager-cache: "false"
30+
# Note: setting up the registry allows auth to be passed via env.NODE_AUTH_TOKEN
31+
registry-url: https://registry.npmjs.org
32+
2633
- name: Prepare
2734
id: prepare
2835
shell: bash
@@ -100,16 +107,15 @@ runs:
100107
shell: bash
101108
working-directory: ${{ inputs.package_dir }}
102109
env:
103-
NPM_TOKEN: ${{ inputs.api_token }}
110+
NODE_AUTH_TOKEN: ${{ inputs.api_token }}
104111
run: |
105112
echo "Publish '${{ steps.prepare.outputs.package_name }}"' package"
106-
npm set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}"
107-
if [ -z "${NPM_TOKEN}" -a "${{ inputs.dry_run }}" == "true" ]; then
113+
if [ -z "${NODE_AUTH_TOKEN}" -a "${{ inputs.dry_run }}" == "true" ]; then
108114
echo "Warning: An NPM access token is required for authentication and has not been provided."
109115
else
110116
npm whoami
111117
fi
112-
118+
113119
if [ "${{ inputs.dry_run }}" == "false" ]; then
114120
dry_run_option=""
115121
else
@@ -122,10 +128,9 @@ runs:
122128
shell: bash
123129
working-directory: ${{ inputs.package_dir }}
124130
env:
125-
NPM_TOKEN: ${{ inputs.api_token }}
131+
NODE_AUTH_TOKEN: ${{ inputs.api_token }}
126132
run: |
127133
echo "Promote '${{ steps.prepare.outputs.package_name }}' package version '${{ steps.prepare.outputs.package_local_version }}' from 'next' to 'latest'"
128-
npm set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}"
129134
npm whoami
130135
npm dist-tag add ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} latest
131136
npm dist-tag rm ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} next

0 commit comments

Comments
 (0)