diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a5c5def..3d6c5a9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -62,13 +62,29 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: '20' + node-version: '22' registry-url: 'https://registry.npmjs.org' + # Upgrade npm to a version that supports OIDC trusted publishing (>= 11.5.1) + - name: Upgrade npm for OIDC trusted publishing + run: npm install -g npm@latest + - run: npm ci - run: npm run build - - run: npm publish --provenance --access public - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Determine npm dist-tag from package.json + id: dist_tag + run: | + VERSION=$(node -p "require('./package.json').version") + if [[ "$VERSION" == *-* ]]; then + echo "npm_tag=next" >> "$GITHUB_OUTPUT" + echo "Publishing pre-release $VERSION to @next" + else + echo "npm_tag=latest" >> "$GITHUB_OUTPUT" + echo "Publishing $VERSION to @latest" + fi + + # Authentication via OIDC trusted publisher (configured on npmjs.com). + # No NPM_TOKEN needed. + - run: npm publish --provenance --access public --tag ${{ steps.dist_tag.outputs.npm_tag }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 739761b..3daa51d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -69,10 +69,14 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20' + node-version: '22' cache: 'npm' registry-url: 'https://registry.npmjs.org' + # Upgrade npm to a version that supports OIDC trusted publishing (>= 11.5.1) + - name: Upgrade npm for OIDC trusted publishing + run: npm install -g npm@latest + - name: Install dependencies run: npm ci @@ -93,10 +97,10 @@ jobs: echo "Publishing $TAG to @latest" fi + # Authentication via OIDC trusted publisher (configured on npmjs.com). + # No NPM_TOKEN needed. - name: Publish to npm run: npm publish --provenance --access public --tag ${{ steps.dist_tag.outputs.npm_tag }} - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Create GitHub Release uses: softprops/action-gh-release@v1