Skip to content

Commit 859d866

Browse files
committed
use napi-rs
make a yarn workspace
1 parent 25c3951 commit 859d866

25 files changed

+2350
-8
lines changed
+227
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
name: node-js builds
2+
env:
3+
DEBUG: napi:*
4+
APP_NAME: cpp-linter
5+
MACOSX_DEPLOYMENT_TARGET: '10.13'
6+
permissions:
7+
contents: write
8+
id-token: write
9+
on:
10+
push:
11+
branches:
12+
- main
13+
tags-ignore:
14+
- '**'
15+
paths-ignore:
16+
- '**/*.md'
17+
- LICENSE
18+
- '**/*.gitignore'
19+
- .editorconfig
20+
- docs/**
21+
pull_request: null
22+
jobs:
23+
build:
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
settings:
28+
- host: macos-latest
29+
target: x86_64-apple-darwin
30+
build: yarn build --target x86_64-apple-darwin --features openssl-vendored
31+
- host: windows-latest
32+
build: yarn build --target x86_64-pc-windows-msvc
33+
target: x86_64-pc-windows-msvc
34+
- host: ubuntu-latest
35+
target: x86_64-unknown-linux-gnu
36+
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
37+
build: yarn build --target x86_64-unknown-linux-gnu --features openssl-vendored
38+
name: stable - ${{ matrix.settings.target }} - node@20
39+
runs-on: ${{ matrix.settings.host }}
40+
steps:
41+
- uses: actions/checkout@v4
42+
- name: Setup node
43+
uses: actions/setup-node@v4
44+
if: ${{ !matrix.settings.docker }}
45+
with:
46+
node-version: 20
47+
cache: yarn
48+
- name: Install
49+
uses: dtolnay/rust-toolchain@stable
50+
if: ${{ !matrix.settings.docker }}
51+
with:
52+
toolchain: stable
53+
targets: ${{ matrix.settings.target }}
54+
- name: Cache cargo
55+
uses: actions/cache@v4
56+
with:
57+
path: |
58+
~/.cargo/registry/index/
59+
~/.cargo/registry/cache/
60+
~/.cargo/git/db/
61+
.cargo-cache
62+
target/
63+
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
64+
- uses: goto-bus-stop/setup-zig@v2
65+
if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' || matrix.settings.target == 'armv7-unknown-linux-musleabihf' }}
66+
with:
67+
version: 0.13.0
68+
- name: Setup toolchain
69+
run: ${{ matrix.settings.setup }}
70+
if: ${{ matrix.settings.setup }}
71+
shell: bash
72+
- name: Setup node x86
73+
working-directory: node-binding
74+
if: matrix.settings.target == 'i686-pc-windows-msvc'
75+
run: yarn config set supportedArchitectures.cpu "ia32"
76+
shell: bash
77+
- name: Install dependencies
78+
working-directory: node-binding
79+
run: yarn install
80+
- name: Setup node x86
81+
uses: actions/setup-node@v4
82+
if: matrix.settings.target == 'i686-pc-windows-msvc'
83+
with:
84+
node-version: 20
85+
cache: yarn
86+
architecture: x86
87+
- name: Build in docker
88+
uses: addnab/docker-run-action@v3
89+
if: ${{ matrix.settings.docker }}
90+
with:
91+
image: ${{ matrix.settings.docker }}
92+
options: >-
93+
--user 0:0
94+
-v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db
95+
-v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache
96+
-v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index
97+
-v ${{ github.workspace }}:/build
98+
-w /build
99+
run: ${{ matrix.settings.build }}
100+
- name: Build
101+
run: ${{ matrix.settings.build }}
102+
if: ${{ !matrix.settings.docker }}
103+
working-directory: node-binding
104+
shell: bash
105+
- name: Upload artifact
106+
uses: actions/upload-artifact@v4
107+
with:
108+
name: bindings-${{ matrix.settings.target }}
109+
path: node-binding/${{ env.APP_NAME }}.*.node
110+
if-no-files-found: error
111+
test-macOS-windows-binding:
112+
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
113+
needs:
114+
- build
115+
strategy:
116+
fail-fast: false
117+
matrix:
118+
settings:
119+
- host: macos-latest
120+
target: x86_64-apple-darwin
121+
- host: windows-latest
122+
target: x86_64-pc-windows-msvc
123+
node:
124+
- '18'
125+
- '20'
126+
runs-on: ${{ matrix.settings.host }}
127+
steps:
128+
- uses: actions/checkout@v4
129+
- name: Setup node
130+
uses: actions/setup-node@v4
131+
with:
132+
node-version: ${{ matrix.node }}
133+
cache: yarn
134+
architecture: x64
135+
- name: Install dependencies
136+
run: yarn install
137+
- name: Download artifacts
138+
uses: actions/download-artifact@v4
139+
with:
140+
name: bindings-${{ matrix.settings.target }}
141+
path: node-binding
142+
- name: List packages
143+
run: ls -R .
144+
working-directory: node-binding
145+
shell: bash
146+
- name: Test bindings
147+
run: yarn test
148+
test-linux-x64-gnu-binding:
149+
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
150+
needs:
151+
- build
152+
strategy:
153+
fail-fast: false
154+
matrix:
155+
node:
156+
- '18'
157+
- '20'
158+
runs-on: ubuntu-latest
159+
steps:
160+
- uses: actions/checkout@v4
161+
- name: Setup node
162+
uses: actions/setup-node@v4
163+
with:
164+
node-version: ${{ matrix.node }}
165+
cache: yarn
166+
- name: Install dependencies
167+
run: yarn install
168+
- name: Download artifacts
169+
uses: actions/download-artifact@v4
170+
with:
171+
name: bindings-x86_64-unknown-linux-gnu
172+
path: node-binding
173+
- name: List packages
174+
run: ls -R .
175+
working-directory: node-binding
176+
shell: bash
177+
- name: Test bindings
178+
run: >-
179+
docker run --rm
180+
-v $(pwd):/build
181+
-w /build
182+
node:${{ matrix.node }}-slim
183+
yarn test
184+
publish:
185+
name: Publish
186+
runs-on: ubuntu-latest
187+
needs:
188+
- test-macOS-windows-binding
189+
- test-linux-x64-gnu-binding
190+
steps:
191+
- uses: actions/checkout@v4
192+
- name: Setup node
193+
uses: actions/setup-node@v4
194+
with:
195+
node-version: 20
196+
cache: yarn
197+
- name: Install dependencies
198+
run: yarn install
199+
- name: Download all artifacts
200+
uses: actions/download-artifact@v4
201+
with:
202+
path: node-binding/artifacts
203+
- name: Move artifacts
204+
working-directory: node-binding
205+
run: yarn artifacts
206+
- name: List packages
207+
run: ls -R ./npm
208+
working-directory: node-binding
209+
shell: bash
210+
- name: Publish
211+
working-directory: node-binding
212+
run: |
213+
npm config set provenance true
214+
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
215+
then
216+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
217+
npm publish --access public
218+
elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
219+
then
220+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
221+
npm publish --tag next --access public
222+
else
223+
echo "Not a release, skipping publish"
224+
fi
225+
env:
226+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
227+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)