From 5acdf9c00d44004dbba99889d6179e03da41fa10 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 5 Oct 2026 12:55:08 +0530 Subject: [PATCH] chore(release): publish to npm with trusted publishing Publish on release:published from release.yml instead of on every push to master, so the npm trusted publisher can be keyed on the filename and a person creating the GitHub release is what publishes; drop the NPM_TOKEN passed to JS-DevTools/npm-publish in favour of id-token: write (OIDC), run on Node 24 with npm@latest (trusted publishing needs npm >= 11.5.1), check out the release tag without persisted credentials. The auto-tag and create-release steps go away with the trigger; the tarball is attached to the release from a separate job with gh release upload instead of the archived upload-release-asset action. GitHub pre-releases go to the beta dist-tag. Co-Authored-By: Claude Fable 5.1 --- .github/workflows/release.yml | 105 ++++++++++++---------------------- 1 file changed, 38 insertions(+), 67 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 964fa22..7a61615 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,77 +1,48 @@ -name: Release - +name: Publish package to npmjs registry on: - push: - branches: [master] + release: + types: [published] jobs: - build: + publish-npm: runs-on: ubuntu-latest + permissions: + contents: read + id-token: write steps: - # Checkout the repository - - name: Checkout repository - uses: actions/checkout@v4 - - # Setup Node.js environment - - name: Setup Node.js - uses: actions/setup-node@v4 + - uses: actions/checkout@v7 with: - node-version: "22.x" - - # Install dependencies - - name: Install dependencies - run: npm install - - # Fetch package details (name and version) - - name: Get package details - id: package - uses: codex-team/action-nodejs-package-info@v1.1 - - # Install npm-pack-all to create a package archive - - name: Install npm pack - run: npm install npm-pack - - # Pack the package into a .tgz archive - - name: Pack the npm package - run: npm pack - - # Publish the package to npm - - name: Publish to npm - id: publish_npm - uses: JS-DevTools/npm-publish@v3 + ref: ${{ github.event.release.tag_name }} + persist-credentials: false + - uses: actions/setup-node@v7 with: - token: ${{ secrets.NPM_TOKEN }} - # access: public # Uncomment this line if you want to publish the package as public for first time - - # Auto-tag the new version if a change is detected - - name: Auto-tag new version - id: update_tag - uses: Klemensas/action-autotag@stable + node-version: 24 + registry-url: https://registry.npmjs.org/ + cache: 'npm' + - run: npm ci + - name: Update npm + run: npm install -g npm@latest + - name: Release + run: npm publish --access public --tag ${{ github.event.release.prerelease && 'beta' || 'latest' }} + + upload-release-asset: + runs-on: ubuntu-latest + needs: publish-npm + permissions: + contents: write + steps: + - uses: actions/checkout@v7 with: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - tag_prefix: "v" - - # Create a new GitHub Release - - name: Create GitHub Release - if: steps.update_tag.outputs.tagname != '' - uses: actions/create-release@v1 - id: create_release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ref: ${{ github.event.release.tag_name }} + persist-credentials: false + - uses: actions/setup-node@v7 with: - tag_name: ${{ steps.update_tag.outputs.tagname }} - release_name: Release ${{ steps.update_tag.outputs.tagname }} - draft: false - prerelease: false - - # Upload the packaged .tgz file as a release asset - - name: Upload Release Asset - if: steps.update_tag.outputs.tagname != '' - uses: actions/upload-release-asset@v1 + node-version: 24 + cache: 'npm' + - run: npm ci + - name: Pack + run: npm pack + - name: Attach the tarball to the release + run: gh release upload "${{ github.event.release.tag_name }}" ./*.tgz --clobber env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: "./contentstack-datasync-mongodb-sdk-${{ steps.package.outputs.version }}.tgz" - asset_name: "contentstack-datasync-mongodb-sdk-${{ steps.package.outputs.version }}.tgz" - asset_content_type: application/tgz + GH_TOKEN: ${{ github.token }}