# https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages # Requires repo secret: NPM_TOKEN ("automation" access token) name: Node.js Publish on: release: types: - published workflow_dispatch: jobs: node-publish: permissions: # actions/checkout@v4 contents: read # `npm publish --provenance` id-token: write # thollander/actions-comment-pull-request pull-requests: write runs-on: ubuntu-latest steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 with: submodules: 'recursive' - uses: volta-cli/action@5c175f92dea6f48441c436471e6479dbc192e194 # v4.2.1 with: registry-url: 'https://registry.npmjs.org' - uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 with: path: | ~/.npm ~\AppData\Roaming\npm-cache key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-npm- ${{ runner.os }}- - run: npm ci - id: publish name: npm publish run: | set -x npm whoami npm publish { echo "PACKAGE_NAME=$(jq --raw-output '.name' package.json)" echo "PACKAGE_VERSION=$(jq --raw-output '.version' package.json)" } >> "${GITHUB_OUTPUT}" env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # Comment back on the PR that caused this push - id: pr-finder run: | GIT_SHA=$(git rev-parse HEAD) echo "${GIT_SHA}" PR_NUMBER=$(curl -L \ --fail-with-body \ --silent \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GIT_SHA}/pulls" \ | jq --raw-output '.[0].number') echo "PR_NUMBER=${PR_NUMBER}" >> "${GITHUB_OUTPUT}" - uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1 with: message: | ## :package: npm publish This pull request resulted in the npm release: [v${{ steps.publish.outputs.PACKAGE_VERSION }}](https://www.npmjs.com/package/${{ steps.publish.outputs.PACKAGE_NAME }}/v/${{ steps.publish.outputs.PACKAGE_VERSION }}). _Comment generated by the [${{ github.workflow }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}) workflow._ comment-tag: node-publish pr-number: ${{ steps.pr-finder.outputs.PR_NUMBER }}