Skip to content

Commit 8705f23

Browse files
authored
chore: update npm publishing to use OIDC authentication (#213)
This updates the CI workflow to use OIDC authentication for npm publishing instead of static tokens. This is more secure and follows GitHub's recommended practices. Changes: - Added 'permissions: id-token: write' to publish job - Removed NPM_TOKEN from environment variables - Removed npm config set command that configured static token authentication - Updated npm publish commands to use npx -y npm@latest publish wrapped in a publish() function - Removed the env block containing NPM_TOKEN secret
1 parent e66c2d9 commit 8705f23

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jobs:
3333
needs: [ compile ]
3434
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
3535
runs-on: ubuntu-latest
36+
permissions:
37+
id-token: write # Required for OIDC
3638
steps:
3739
- name: Checkout repo
3840
uses: actions/checkout@v3
@@ -45,13 +47,13 @@ jobs:
4547

4648
- name: Publish to npm
4749
run: |
48-
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
50+
publish() { # use latest npm to ensure OIDC support
51+
npx -y npm@latest publish "$@"
52+
}
4953
if [[ ${GITHUB_REF} == *alpha* ]]; then
50-
npm publish --access public --tag alpha
54+
publish --access public --tag alpha
5155
elif [[ ${GITHUB_REF} == *beta* ]]; then
52-
npm publish --access public --tag beta
56+
publish --access public --tag beta
5357
else
54-
npm publish --access public
55-
fi
56-
env:
57-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
58+
publish --access public
59+
fi

0 commit comments

Comments
 (0)