Skip to content

Commit d1dd97b

Browse files
committed
feat: add release ci
1 parent 47d4b65 commit d1dd97b

File tree

2 files changed

+260
-0
lines changed

2 files changed

+260
-0
lines changed

.github/workflows/release.yml

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
settings:
19+
- host: macos-latest
20+
target: x86_64-apple-darwin
21+
build: pnpm build --target x86_64-apple-darwin
22+
- host: macos-latest
23+
target: aarch64-apple-darwin
24+
build: pnpm build --target aarch64-apple-darwin
25+
- host: windows-latest
26+
target: x86_64-pc-windows-msvc
27+
build: pnpm build --target x86_64-pc-windows-msvc
28+
- host: windows-latest
29+
target: i686-pc-windows-msvc
30+
build: pnpm build --target i686-pc-windows-msvc
31+
- host: windows-latest
32+
target: aarch64-pc-windows-msvc
33+
build: pnpm build --target aarch64-pc-windows-msvc
34+
- host: ubuntu-latest
35+
target: x86_64-unknown-linux-gnu
36+
build: pnpm build --target x86_64-unknown-linux-gnu --use-napi-cross
37+
- host: ubuntu-latest
38+
target: x86_64-unknown-linux-musl
39+
build: pnpm build --target x86_64-unknown-linux-musl -x
40+
- host: ubuntu-latest
41+
target: aarch64-unknown-linux-gnu
42+
build: pnpm build --target aarch64-unknown-linux-gnu --use-napi-cross
43+
- host: ubuntu-latest
44+
target: aarch64-unknown-linux-musl
45+
build: pnpm build --target aarch64-unknown-linux-musl -x
46+
- host: ubuntu-latest
47+
target: armv7-unknown-linux-gnueabihf
48+
build: pnpm build --target armv7-unknown-linux-gnueabihf --use-napi-cross
49+
- host: ubuntu-latest
50+
target: aarch64-unknown-linux-ohos
51+
build: pnpm build --target aarch64-unknown-linux-ohos -x
52+
- host: ubuntu-latest
53+
target: aarch64-linux-android
54+
build: pnpm build --target aarch64-linux-android --use-napi-cross
55+
- host: ubuntu-latest
56+
target: x86_64-unknown-freebsd
57+
build: pnpm build --target x86_64-unknown-freebsd --use-napi-cross
58+
59+
name: Build - ${{ matrix.settings.target }}
60+
runs-on: ${{ matrix.settings.host }}
61+
62+
steps:
63+
- uses: actions/checkout@v5
64+
65+
- name: Setup pnpm
66+
uses: pnpm/action-setup@v2
67+
68+
- name: Setup node
69+
uses: actions/setup-node@v4
70+
with:
71+
node-version: 20
72+
cache: pnpm
73+
74+
- name: Install dependencies
75+
run: pnpm install
76+
77+
- name: Setup Rust
78+
uses: dtolnay/rust-toolchain@stable
79+
with:
80+
targets: ${{ matrix.settings.target }}
81+
82+
- name: Cache cargo
83+
uses: actions/cache@v4
84+
with:
85+
path: |
86+
~/.cargo/registry/index/
87+
~/.cargo/registry/cache/
88+
~/.cargo/git/db/
89+
.cargo-cache
90+
target/
91+
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
92+
93+
- name: Setup toolchain
94+
run: ${{ matrix.settings.setup }}
95+
if: ${{ matrix.settings.setup }}
96+
shell: bash
97+
98+
- name: Build
99+
run: ${{ matrix.settings.build }}
100+
shell: bash
101+
102+
- name: Upload artifact
103+
uses: actions/upload-artifact@v4
104+
with:
105+
name: bindings-${{ matrix.settings.target }}
106+
path: dist/*.node
107+
if-no-files-found: error
108+
109+
build-wasm:
110+
name: Build - wasm32-wasip1-threads
111+
runs-on: ubuntu-latest
112+
113+
steps:
114+
- uses: actions/checkout@v5
115+
116+
- name: Setup pnpm
117+
uses: pnpm/action-setup@v2
118+
119+
- name: Setup node
120+
uses: actions/setup-node@v4
121+
with:
122+
node-version: 20
123+
cache: pnpm
124+
125+
- name: Install dependencies
126+
run: pnpm install
127+
128+
- name: Setup Rust
129+
uses: dtolnay/rust-toolchain@stable
130+
with:
131+
targets: wasm32-wasip1-threads
132+
133+
- name: Cache cargo
134+
uses: actions/cache@v4
135+
with:
136+
path: |
137+
~/.cargo/registry/index/
138+
~/.cargo/registry/cache/
139+
~/.cargo/git/db/
140+
.cargo-cache
141+
target/
142+
key: wasm32-wasip1-threads-cargo-ubuntu-latest
143+
144+
- name: Build
145+
run: pnpm build --target wasm32-wasip1-threads
146+
147+
- name: Upload artifact
148+
uses: actions/upload-artifact@v4
149+
with:
150+
name: bindings-wasm32-wasip1-threads
151+
path: dist/*.wasm
152+
if-no-files-found: error
153+
154+
universal-macOS:
155+
name: Build universal macOS binary
156+
needs:
157+
- build
158+
runs-on: macos-latest
159+
steps:
160+
- uses: actions/checkout@v5
161+
162+
- name: Setup pnpm
163+
uses: pnpm/action-setup@v2
164+
165+
- name: Setup node
166+
uses: actions/setup-node@v4
167+
with:
168+
node-version: 20
169+
cache: pnpm
170+
171+
- name: Install dependencies
172+
run: pnpm install
173+
174+
- name: Download macOS x64 artifact
175+
uses: actions/download-artifact@v4
176+
with:
177+
name: bindings-x86_64-apple-darwin
178+
path: artifacts
179+
180+
- name: Download macOS arm64 artifact
181+
uses: actions/download-artifact@v4
182+
with:
183+
name: bindings-aarch64-apple-darwin
184+
path: artifacts
185+
186+
- name: Combine binaries
187+
run: pnpm universal
188+
189+
- name: Upload artifact
190+
uses: actions/upload-artifact@v4
191+
with:
192+
name: bindings-universal-apple-darwin
193+
path: dist/*.node
194+
if-no-files-found: error
195+
196+
publish:
197+
name: Publish to NPM
198+
runs-on: ubuntu-latest
199+
needs:
200+
- build
201+
- build-wasm
202+
- universal-macOS
203+
204+
steps:
205+
- uses: actions/checkout@v5
206+
207+
- name: Setup pnpm
208+
uses: pnpm/action-setup@v2
209+
210+
- name: Setup node
211+
uses: actions/setup-node@v4
212+
with:
213+
node-version: 20
214+
cache: pnpm
215+
216+
- name: Install dependencies
217+
run: pnpm install
218+
219+
- name: Download all artifacts
220+
uses: actions/download-artifact@v4
221+
with:
222+
path: artifacts
223+
224+
- name: Move artifacts
225+
run: pnpm artifacts
226+
227+
- name: List packages
228+
run: ls -R ./npm
229+
shell: bash
230+
231+
- name: Publish
232+
run: |
233+
npm config set provenance true
234+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
235+
npm publish --access public
236+
env:
237+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
238+

package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,30 @@
1010
"main": "dist/index.js",
1111
"scripts": {
1212
"build": "napi build --release --output-dir dist",
13+
"build:debug": "napi build --output-dir dist",
14+
"universal": "napi universalify",
15+
"prepublishOnly": "napi prepublish -t npm",
16+
"artifacts": "napi artifacts",
1317
"test": "vitest"
1418
},
19+
"napi": {
20+
"targets": [
21+
"x86_64-apple-darwin",
22+
"x86_64-pc-windows-msvc",
23+
"x86_64-unknown-linux-gnu",
24+
"x86_64-unknown-linux-musl",
25+
"x86_64-unknown-freebsd",
26+
"i686-pc-windows-msvc",
27+
"armv7-unknown-linux-gnueabihf",
28+
"aarch64-unknown-linux-gnu",
29+
"aarch64-apple-darwin",
30+
"aarch64-unknown-linux-musl",
31+
"aarch64-unknown-linux-ohos",
32+
"aarch64-pc-windows-msvc",
33+
"aarch64-linux-android",
34+
"wasm32-wasip1-threads"
35+
]
36+
},
1537
"devDependencies": {
1638
"@antfu/eslint-config": "^5.4.1",
1739
"@types/node": "^24.6.2",

0 commit comments

Comments
 (0)