Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/release-prebuilt-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-<os>-<cpu>` 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.
3 changes: 3 additions & 0 deletions scripts/prebuilt-package-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,20 @@ 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"),
);

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",
});
Expand Down
4 changes: 4 additions & 0 deletions scripts/prebuilt-package-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -150,6 +153,7 @@ export function buildPlatformPackageManifest(
dunk: `./bin/${binaryName}`,
},
files: ["bin", "LICENSE"],
repository: rootPackage.repository,
license: rootPackage.license,
publishConfig: {
access: "public",
Expand Down
3 changes: 2 additions & 1 deletion scripts/publish-prebuilt-npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading