From 910b45c9af24e1427500031b73d6f7b8e657ba88 Mon Sep 17 00:00:00 2001 From: ktechmidas <9920871+ktechmidas@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:34:28 +0300 Subject: [PATCH 1/3] ci: publish to npm with trusted publishing The release job published with the org NPM_TOKEN secret, which npm rejects (E404 on the PUT), so v7.0.6 never reached npm. Publish through npm trusted publishing instead, the way dashcore-lib does: the job gets an OIDC token and npm exchanges it for a publish token. No secret is involved. - The job needs id-token: write, npm 11.5.1 or later and no stored token. - Only GitHub's own actions run in it, pinned to commits. - package.json's repository now names dashpay/dashcore-node. npm checks it against the provenance attestation that trusted publishing adds. - A manual run of the workflow rehearses the publish with --dry-run and fails if npm does not accept the workflow as a trusted publisher. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/test_and_release.yml | 87 +++++++++++++++++--------- package.json | 5 +- 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/.github/workflows/test_and_release.yml b/.github/workflows/test_and_release.yml index 012c612f3..4e5db854c 100644 --- a/.github/workflows/test_and_release.yml +++ b/.github/workflows/test_and_release.yml @@ -46,42 +46,73 @@ jobs: name: Release NPM package runs-on: ubuntu-24.04 needs: test - if: ${{ github.event_name == 'release' }} + # A release publishes the package. A manual run only rehearses the publish: + # it packs the package and checks that npm accepts this workflow as a + # trusted publisher, and publishes nothing. + if: ${{ github.event_name == 'release' || github.event_name == 'workflow_dispatch' }} + # npm trusted publishing: npm exchanges the job's OIDC token for a publish + # token, so no NPM_TOKEN secret is needed + permissions: + contents: read + id-token: write + # Every step here can request an npm publish token, so only GitHub's own + # actions run, pinned to commits, and the checks are plain shell steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 - - uses: actions/setup-node@v4 + # Trusted publishing needs npm 11.5.1 or later. No registry-url: with it, + # setup-node writes a token entry to .npmrc and npm tries token auth + # instead of the OIDC exchange. + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: - node-version: '20' + node-version: '24.14.1' - name: Check package version matches tag - uses: geritol/match-tag-to-package-version@0.1.0 + if: ${{ github.event_name == 'release' }} env: - TAG_PREFIX: refs/tags/v - - - name: Enable NPM cache - uses: actions/cache@v4 - with: - path: '~/.npm' - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: Install NPM dependencies - run: npm ci + RELEASE_TAG: ${{ github.event.release.tag_name }} + run: | + VERSION=$(node -p "require('./package.json').version") + if [ "$RELEASE_TAG" != "v$VERSION" ]; then + echo "::error::Release tag $RELEASE_TAG does not match package version v$VERSION" + exit 1 + fi + # X.Y-dev for dev releases, latest otherwise - name: Set release tag - uses: actions/github-script@v7 id: tag - with: - result-encoding: string - script: | - const tag = context.payload.release.tag_name; - const [, major, minor] = tag.match(/^v([0-9]+)\.([0-9]+)/); - return (tag.includes('dev') ? `${major}.${minor}-dev` : 'latest'); + if: ${{ github.event_name == 'release' }} + env: + RELEASE_TAG: ${{ github.event.release.tag_name }} + run: | + if [[ "$RELEASE_TAG" == *dev* ]]; then + [[ "$RELEASE_TAG" =~ ^v([0-9]+)\.([0-9]+) ]] + echo "result=${BASH_REMATCH[1]}.${BASH_REMATCH[2]}-dev" >> "$GITHUB_OUTPUT" + else + echo "result=latest" >> "$GITHUB_OUTPUT" + fi + # Packs the checkout as earlier releases did. The package has no build + # step, and nothing is installed in this job, so no package script runs + # while the OIDC token is available. Trusted publishing adds a provenance + # attestation, which requires package.json's repository.url to name this + # repository. - name: Publish NPM package - uses: JS-DevTools/npm-publish@v3 - with: - token: ${{ secrets.NPM_TOKEN }} - tag: ${{ steps.tag.outputs.result }} + if: ${{ github.event_name == 'release' }} + env: + NPM_TAG: ${{ steps.tag.outputs.result }} + run: npm publish --ignore-scripts --access public --tag "$NPM_TAG" + + # npm does the OIDC exchange on a dry run too, and without a token a dry + # run only warns, so the result is read from npm's verbose log. The text + # matched is the one printed by the npm that ships with the Node version + # pinned above. + - name: Rehearse the publish + if: ${{ github.event_name == 'workflow_dispatch' }} + run: | + LOG="$RUNNER_TEMP/npm-publish-dry-run.log" + npm publish --dry-run --ignore-scripts --access public --loglevel verbose 2>&1 | tee "$LOG" + if ! grep -q 'oidc Successfully retrieved and set token' "$LOG"; then + echo "::error::npm did not accept this workflow as a trusted publisher of this package. See the oidc lines above." + exit 1 + fi diff --git a/package.json b/package.json index 1dec0b08e..985cd885b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,10 @@ "author": "BitPay ", "version": "7.0.6", "main": "./index.js", - "repository": "git://github.com/dashevo/dashcore-node.git", + "repository": { + "type": "git", + "url": "git+https://github.com/dashpay/dashcore-node.git" + }, "homepage": "https://github.com/dashevo/dashcore-node", "bugs": { "url": "https://github.com/dashevo/dashcore-node/issues" From 4ff6129f8aa3950396443cff6b01d1c15bf71c25 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Mon, 23 Nov 2026 15:08:07 +0700 Subject: [PATCH 2/3] ci: rehearse the npm publish from a manual run A manual run (workflow_dispatch) of the release job runs `npm publish --dry-run`, which still does the OIDC token exchange, and fails if npm does not accept this workflow as a trusted publisher of the package. It publishes nothing, so the trusted publisher can be checked, and validated on npm, without cutting a release. A release still publishes as before. Co-authored-by: ktechmidas <9920871+ktechmidas@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test_and_release.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_and_release.yml b/.github/workflows/test_and_release.yml index 9a4f0a986..70765c786 100644 --- a/.github/workflows/test_and_release.yml +++ b/.github/workflows/test_and_release.yml @@ -46,7 +46,10 @@ jobs: name: Release NPM package runs-on: ubuntu-24.04 needs: test - if: ${{ github.event_name == 'release' }} + # A release publishes the package. A manual run only rehearses the publish: + # it checks that npm accepts this workflow as a trusted publisher, and + # publishes nothing. + if: ${{ github.event_name == 'release' || github.event_name == 'workflow_dispatch' }} # npm trusted publishing: npm exchanges the job's OIDC token for a publish # token, so no NPM_TOKEN secret is needed permissions: @@ -65,6 +68,7 @@ jobs: node-version: '24.14.1' - name: Check package version matches tag + if: ${{ github.event_name == 'release' }} env: RELEASE_TAG: ${{ github.event.release.tag_name }} run: | @@ -77,6 +81,7 @@ jobs: # X.Y-dev for dev releases, latest otherwise - name: Set release tag id: tag + if: ${{ github.event_name == 'release' }} env: RELEASE_TAG: ${{ github.event.release.tag_name }} run: | @@ -93,6 +98,21 @@ jobs: # repository.url to name this repository. --loglevel verbose is the only # level at which npm logs why an OIDC token exchange failed. - name: Publish NPM package + if: ${{ github.event_name == 'release' }} env: NPM_TAG: ${{ steps.tag.outputs.result }} run: npm publish --ignore-scripts --access public --tag "$NPM_TAG" --loglevel verbose + + # npm does the OIDC exchange on a dry run too, and without a token a dry + # run only warns, so the result is read from npm's verbose log. The text + # matched is the one printed by the npm that ships with the Node version + # pinned above. + - name: Rehearse the publish + if: ${{ github.event_name == 'workflow_dispatch' }} + run: | + LOG="$RUNNER_TEMP/npm-publish-dry-run.log" + npm publish --dry-run --ignore-scripts --access public --loglevel verbose 2>&1 | tee "$LOG" + if ! grep -q 'oidc Successfully retrieved and set token' "$LOG"; then + echo "::error::npm did not accept this workflow as a trusted publisher of this package. See the oidc lines above." + exit 1 + fi From 7695cb755fa86177a7aefdd4f6d939f1dae44d9f Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Mon, 23 Nov 2026 15:13:25 +0700 Subject: [PATCH 3/3] ci: pass a tag to the publish rehearsal npm refuses to publish a prerelease version without --tag, even on a dry run, and does so before the OIDC token exchange. A rehearsal of a dev version would then miss the oidc log line and report a trusted publisher failure. The dry run never applies the tag. Checked locally: a 7.1.0-dev.1 dry run fails with "You must specify a tag" without --tag and goes on to "Publishing ... with tag rehearsal" with it. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test_and_release.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_and_release.yml b/.github/workflows/test_and_release.yml index 70765c786..2701522a5 100644 --- a/.github/workflows/test_and_release.yml +++ b/.github/workflows/test_and_release.yml @@ -106,12 +106,14 @@ jobs: # npm does the OIDC exchange on a dry run too, and without a token a dry # run only warns, so the result is read from npm's verbose log. The text # matched is the one printed by the npm that ships with the Node version - # pinned above. + # pinned above. The explicit --tag is needed because npm rejects a + # prerelease version without one before the exchange; a dry run never + # applies it. - name: Rehearse the publish if: ${{ github.event_name == 'workflow_dispatch' }} run: | LOG="$RUNNER_TEMP/npm-publish-dry-run.log" - npm publish --dry-run --ignore-scripts --access public --loglevel verbose 2>&1 | tee "$LOG" + npm publish --dry-run --ignore-scripts --access public --tag rehearsal --loglevel verbose 2>&1 | tee "$LOG" if ! grep -q 'oidc Successfully retrieved and set token' "$LOG"; then echo "::error::npm did not accept this workflow as a trusted publisher of this package. See the oidc lines above." exit 1