From c536661a5d2f1935685bf781c9beafae4dc3ccbd Mon Sep 17 00:00:00 2001 From: Amir Date: Tue, 10 Nov 2026 09:46:03 +0100 Subject: [PATCH 1/2] ci(release): publish via npm trusted publishing instead of a stored token The npm environment's NPM_TOKEN is rejected (401), and npm now requires 2FA for direct publishing, so a replacement token would hit the same wall. - Publish job requests an OIDC token (id-token: write) and installs npm 11.21.2, since trusted publishing needs npm 11.5.1+ and Node 22 ships npm 10. - Platform packages now carry `repository`; npm rejects the automatic provenance attestation when it is missing. - The publish script inherits stdin so a local publish can answer npm's 2FA prompt; with stdin ignored, npm fails with EOTP before offering it. --- .github/workflows/release-prebuilt-npm.yml | 15 ++++++++------- CONTRIBUTING.md | 3 ++- scripts/prebuilt-package-helpers.test.ts | 3 +++ scripts/prebuilt-package-helpers.ts | 4 ++++ scripts/publish-prebuilt-npm.ts | 3 ++- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release-prebuilt-npm.yml b/.github/workflows/release-prebuilt-npm.yml index ad1e2d5..32203d1 100644 --- a/.github/workflows/release-prebuilt-npm.yml +++ b/.github/workflows/release-prebuilt-npm.yml @@ -124,6 +124,10 @@ jobs: - stage-release if: github.event_name == 'push' || inputs.publish == true environment: npm + # npm trusted publishing: the job's OIDC token replaces a stored npm token. + permissions: + contents: read + id-token: write steps: - name: Check out repository uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 @@ -139,6 +143,10 @@ jobs: node-version: 22 registry-url: https://registry.npmjs.org + # Trusted publishing needs npm 11.5.1+; Node 22 bundles npm 10. + - name: Install npm with trusted publishing support + run: npm install -g npm@11.21.2 + - name: Install dependencies run: bun install --frozen-lockfile @@ -151,14 +159,7 @@ jobs: - name: Show staged packages run: find dist/release/npm -maxdepth 3 -type f | sort - - name: Verify npm auth - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - run: npm whoami - - name: Publish packages - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: bun run publish:prebuilt:npm -- --tag "${{ github.event_name == 'workflow_dispatch' && inputs.npm_tag || ((contains(github.ref_name, '-alpha') || contains(github.ref_name, '-beta') || contains(github.ref_name, '-rc')) && 'beta' || 'latest') }}" create-github-release: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5af57ea..2eb6647 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -124,4 +124,5 @@ Key rules: - The npm package name is `dunkdiff`. - The installed CLI command is `dunk`. -- The automated prebuilt publish workflow lives in `.github/workflows/release-prebuilt-npm.yml`. +- The automated prebuilt publish workflow lives in `.github/workflows/release-prebuilt-npm.yml`. It publishes through npm trusted publishing, so no npm token is stored in the repo. Each of the five packages (`dunkdiff` and the four `dunkdiff--` packages) needs a trusted publisher on npmjs.com for `amix/dunk`, workflow `release-prebuilt-npm.yml`, environment `npm`, with `npm publish` allowed. +- To publish from your own machine instead, run `bun run publish:prebuilt:npm -- --tag latest` in a terminal so npm can prompt for 2FA. diff --git a/scripts/prebuilt-package-helpers.test.ts b/scripts/prebuilt-package-helpers.test.ts index b36bb48..46f4a42 100644 --- a/scripts/prebuilt-package-helpers.test.ts +++ b/scripts/prebuilt-package-helpers.test.ts @@ -84,10 +84,12 @@ describe("prebuilt package helpers", () => { }); test("buildPlatformPackageManifest declares the native binary as a bin entry", () => { + const repository = { type: "git", url: "git+https://github.com/amix/dunk.git" }; const manifest = buildPlatformPackageManifest( { version: "1.2.3", description: "Desktop diff viewer", + repository, license: "MIT", }, getPlatformPackageSpecForHost("linux", "x64"), @@ -95,6 +97,7 @@ describe("prebuilt package helpers", () => { expect(manifest.name).toBe("dunkdiff-linux-x64"); expect(manifest.version).toBe("1.2.3"); + expect(manifest.repository).toEqual(repository); expect(manifest.bin).toEqual({ dunk: "./bin/dunk", }); diff --git a/scripts/prebuilt-package-helpers.ts b/scripts/prebuilt-package-helpers.ts index d40b7d2..253cf4b 100644 --- a/scripts/prebuilt-package-helpers.ts +++ b/scripts/prebuilt-package-helpers.ts @@ -129,11 +129,14 @@ export function binaryFilenameForSpec(spec: PlatformPackageSpec) { * * Declaring the native binary in `bin` makes npm restore execute bits on install, * including root-owned global installs where the JS wrapper cannot chmod later. + * `repository` must match the publishing repo, or npm rejects the provenance + * attestation that trusted publishing attaches. */ export function buildPlatformPackageManifest( rootPackage: { version: string; description?: string; + repository?: unknown; license?: string; }, spec: PlatformPackageSpec, @@ -150,6 +153,7 @@ export function buildPlatformPackageManifest( dunk: `./bin/${binaryName}`, }, files: ["bin", "LICENSE"], + repository: rootPackage.repository, license: rootPackage.license, publishConfig: { access: "public", diff --git a/scripts/publish-prebuilt-npm.ts b/scripts/publish-prebuilt-npm.ts index 8069999..f90e03a 100644 --- a/scripts/publish-prebuilt-npm.ts +++ b/scripts/publish-prebuilt-npm.ts @@ -70,9 +70,10 @@ function publishDirectory(directory: string, dryRun: boolean, npmTag: string) { args.push("--dry-run"); } + // Inherit stdin so a local publish can answer npm's 2FA prompt; npm only offers it on a TTY. const proc = Bun.spawnSync(["npm", ...args], { cwd: directory, - stdin: "ignore", + stdin: "inherit", stdout: "inherit", stderr: "inherit", env: process.env, From d4bff19a117256a12e1e6ec6587c79c04d6241a4 Mon Sep 17 00:00:00 2001 From: Amir Date: Tue, 10 Nov 2026 09:46:46 +0100 Subject: [PATCH 2/2] docs(contributing): note npm's 2-day trusted publisher expiry --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2eb6647..b31cc51 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -124,5 +124,5 @@ Key rules: - The npm package name is `dunkdiff`. - The installed CLI command is `dunk`. -- The automated prebuilt publish workflow lives in `.github/workflows/release-prebuilt-npm.yml`. It publishes through npm trusted publishing, so no npm token is stored in the repo. Each of the five packages (`dunkdiff` and the four `dunkdiff--` packages) needs a trusted publisher on npmjs.com for `amix/dunk`, workflow `release-prebuilt-npm.yml`, environment `npm`, with `npm publish` allowed. +- The automated prebuilt publish workflow lives in `.github/workflows/release-prebuilt-npm.yml`. It publishes through npm trusted publishing, so no npm token is stored in the repo. Each of the five packages (`dunkdiff` and the four `dunkdiff--` packages) needs a trusted publisher on npmjs.com for `amix/dunk`, workflow `release-prebuilt-npm.yml`, environment `npm`, with `npm publish` allowed. A new trusted publisher expires unless it publishes within 2 days, so add it shortly before tagging. - To publish from your own machine instead, run `bun run publish:prebuilt:npm -- --tag latest` in a terminal so npm can prompt for 2FA.