Skip to content

Commit fb20a7e

Browse files
committed
chore: update npm publishing to use OIDC authentication
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 for OIDC authentication - Removed NPM_TOKEN from environment variables in publish job - Removed 'npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}' command - Added publish() helper function that wraps 'npx -y npm@latest publish "$@"' - Replaced direct 'npm publish' commands with 'publish' function calls
1 parent 5f87245 commit fb20a7e

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
needs: [ compile, test ]
3636
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
3737
runs-on: ubuntu-latest
38+
permissions:
39+
id-token: write # Required for OIDC
3840
steps:
3941
- name: Checkout repo
4042
uses: actions/checkout@v3
@@ -47,13 +49,13 @@ jobs:
4749

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

0 commit comments

Comments
 (0)