Skip to content

Commit c59ffbb

Browse files
committed
Add platform package publish workflow and Rust cache
1 parent 7779456 commit c59ffbb

5 files changed

Lines changed: 162 additions & 3 deletions

File tree

.cspell/project-words.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ mkdirs
3232
nothrow
3333
notificationcenter
3434
notifysend
35+
npmjs
3536
oclif
3637
outdir
3738
oxfmt
@@ -50,6 +51,8 @@ revparse
5051
sindre
5152
sorhus
5253
sourcemaps
54+
swtinem
55+
swatinem
5356
sprintln
5457
sprintlns
5558
stefanzweifel

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ jobs:
9292
with:
9393
targets: ${{ matrix.target }}
9494

95+
- name: Cache Rust build
96+
uses: Swatinem/rust-cache@v2
97+
with:
98+
shared-key: native-${{ matrix.target }}
99+
95100
- name: Install dependencies
96101
run: pnpm install
97102

.github/workflows/publish.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch:
8+
inputs:
9+
dry_run:
10+
description: "Run npm publish in dry-run mode"
11+
required: false
12+
default: true
13+
type: boolean
14+
15+
jobs:
16+
build-native:
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
- os: macos-latest
22+
target: x86_64-apple-darwin
23+
cross_compile: false
24+
- os: macos-latest
25+
target: aarch64-apple-darwin
26+
cross_compile: false
27+
- os: windows-latest
28+
target: x86_64-pc-windows-msvc
29+
cross_compile: false
30+
- os: windows-latest
31+
target: aarch64-pc-windows-msvc
32+
cross_compile: false
33+
- os: ubuntu-latest
34+
target: x86_64-unknown-linux-gnu
35+
cross_compile: false
36+
- os: ubuntu-latest
37+
target: x86_64-unknown-linux-musl
38+
cross_compile: true
39+
- os: ubuntu-latest
40+
target: aarch64-unknown-linux-gnu
41+
cross_compile: true
42+
- os: ubuntu-latest
43+
target: aarch64-unknown-linux-musl
44+
cross_compile: true
45+
runs-on: ${{ matrix.os }}
46+
steps:
47+
- uses: actions/checkout@v6
48+
49+
- uses: pnpm/action-setup@v4
50+
51+
- uses: actions/setup-node@v6
52+
with:
53+
node-version: 20
54+
cache: pnpm
55+
56+
- name: Install Rust toolchain
57+
uses: dtolnay/rust-toolchain@stable
58+
with:
59+
targets: ${{ matrix.target }}
60+
61+
- name: Cache Rust build
62+
uses: Swatinem/rust-cache@v2
63+
with:
64+
shared-key: native-${{ matrix.target }}
65+
66+
- name: Install dependencies
67+
run: pnpm install
68+
69+
- name: Install Zig
70+
if: matrix.cross_compile
71+
uses: goto-bus-stop/setup-zig@v2
72+
73+
- name: Build native target
74+
if: ${{ !matrix.cross_compile }}
75+
run: pnpm exec napi build --platform --release --target ${{ matrix.target }}
76+
77+
- name: Build native target (cross)
78+
if: matrix.cross_compile
79+
run: pnpm exec napi build --platform --release --cross-compile --target ${{ matrix.target }}
80+
81+
- name: Upload native artifact
82+
uses: actions/upload-artifact@v4
83+
with:
84+
name: bindings-${{ matrix.target }}
85+
path: slatedb-node.*.node
86+
if-no-files-found: error
87+
88+
publish:
89+
runs-on: ubuntu-latest
90+
needs:
91+
- build-native
92+
permissions:
93+
contents: read
94+
id-token: write
95+
steps:
96+
- uses: actions/checkout@v6
97+
98+
- uses: pnpm/action-setup@v4
99+
100+
- uses: actions/setup-node@v6
101+
with:
102+
node-version: 20
103+
cache: pnpm
104+
105+
- name: Install dependencies
106+
run: pnpm install
107+
108+
- name: Download all artifacts
109+
uses: actions/download-artifact@v4
110+
with:
111+
path: artifacts
112+
113+
- name: Create platform package dirs
114+
run: pnpm run create-npm-dirs
115+
116+
- name: Move native binaries into platform packages
117+
run: pnpm run artifacts
118+
119+
- name: Publish package(s)
120+
env:
121+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
122+
run: |
123+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
124+
npm config set provenance true
125+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.dry_run }}" = "true" ]; then
126+
npm publish --access public --dry-run
127+
else
128+
npm publish --access public
129+
fi

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,27 @@ pnpm test
102102

103103
## Prebuilt Binaries
104104

105-
The package is configured for `@napi-rs/cli` prebuilt targets:
105+
The package uses `@napi-rs/cli` optional dependency packages (like `esbuild`/`swc`) so the main package stays small and installs only the binary for the current platform.
106+
107+
Generated optional packages:
106108

107109
- macOS x64 / arm64
108110
- Linux x64 / arm64 (gnu + musl)
109111
- Windows x64 / arm64 (msvc)
110112

111-
CI can build and publish artifacts with `napi prepublish -t npm`.
113+
The generated package names are:
114+
115+
- `slatedb-node-darwin-x64`
116+
- `slatedb-node-darwin-arm64`
117+
- `slatedb-node-linux-x64-gnu`
118+
- `slatedb-node-linux-x64-musl`
119+
- `slatedb-node-linux-arm64-gnu`
120+
- `slatedb-node-linux-arm64-musl`
121+
- `slatedb-node-win32-x64-msvc`
122+
- `slatedb-node-win32-arm64-msvc`
123+
124+
## Publishing
125+
126+
`publish.yml` builds all native targets, downloads artifacts, creates per-platform npm package dirs, and runs `npm publish`.
127+
128+
`prepublishOnly` runs `napi pre-publish -t npm`, which updates `optionalDependencies` and publishes the platform packages alongside the main package.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@
2828
"import": "./lib/index.js"
2929
}
3030
},
31+
"publishConfig": {
32+
"access": "public",
33+
"registry": "https://registry.npmjs.org/"
34+
},
3135
"scripts": {
3236
"artifacts": "napi artifacts",
37+
"create-npm-dirs": "napi create-npm-dirs",
3338
"build": "pnpm run clean && pnpm run build:debug && pnpm run build:ts",
3439
"build:debug": "napi build --platform --no-js --dts target/napi-rs/index.d.ts",
3540
"build:release": "napi build --platform --release --no-js --dts target/napi-rs/index.d.ts",
@@ -40,7 +45,7 @@
4045
"lint:fix": "oxfmt && oxlint --type-aware --fix",
4146
"lint:oxfmt": "oxfmt --check",
4247
"lint:oxlint": "oxlint --type-aware --deny-warnings",
43-
"prepublishOnly": "napi prepublish -t npm --no-js --dts target/napi-rs/index.d.ts",
48+
"prepublishOnly": "napi pre-publish -t npm",
4449
"release": "pnpm run build:release && pnpm run build:ts",
4550
"test": "pnpm run build:debug && pnpm run build:ts && vitest run"
4651
},

0 commit comments

Comments
 (0)