npm now supports trusted publishing, which uses OpenID Connect (OIDC) tokens to authenticate GitHub Actions workflows without requiring manual NPM token management. This is more secure and easier to maintain than the traditional token-based approach.
The GitHub Actions workflow template has been updated to use trusted publishing:
- Permissions updated: Added
id-token: writepermission to enable OIDC token creation - NPM token removed: The
npm-tokenparameter has been removed from the deploy step - Setup instructions updated: Instructions now point to npm's trusted publishing guide
To update your existing adapter to use trusted publishing:
Edit .github/workflows/test-and-release.yml and update the deploy job permissions:
# Deploys the final package to NPM
deploy:
needs: [check-and-lint, adapter-tests]
# Trigger this step only when a commit on any branch is tagged with a version number
if: |
contains(github.event.head_commit.message, '[skip ci]') == false &&
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
# Write permissions are required to create Github releases
permissions:
+ id-token: write
contents: writeIn the same file, remove the npm-token line from the deploy step:
steps:
- uses: ioBroker/testing-action-deploy@v1
with:
node-version: '20.x'
# Uncomment the following line if your adapter cannot be installed using 'npm ci'
# install-command: 'npm install'
build: true
- npm-token: ${{ secrets.NPM_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}Before the workflow can publish to npm using trusted publishing, you need to configure it in your npm account:
- Log in to npmjs.com
- Navigate to your package page
- Go to Settings → Publishing access
- Click Add provider under "Trusted publishers"
- Select GitHub Actions as the provider
- Fill in the following information:
- Repository owner: Your GitHub username or organization (e.g.,
yourname) - Repository name: Your repository name without owner (e.g.,
ioBroker.youradapter) - Workflow name:
test-and-release.yml - Environment name: Leave empty (unless you use GitHub environments)
- Repository owner: Your GitHub username or organization (e.g.,
- Click Add
For detailed instructions, see the npm trusted publishers documentation.
Once you've verified that trusted publishing works correctly, you can remove the NPM_TOKEN secret from your GitHub repository settings (Settings → Secrets and variables → Actions).
- Enhanced security: No need to store long-lived NPM tokens
- Simplified setup: Configure once in your npm account
- Better audit trail: npm can verify releases come from your specified repository
- Automatic token rotation: OIDC tokens are short-lived and automatically managed