Skip to content

Commit 27182e7

Browse files
committed
feat: 初始化项目,增加项目配置验证
0 parents  commit 27182e7

36 files changed

Lines changed: 4339 additions & 0 deletions

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[target.aarch64-unknown-linux-musl]
2+
linker = "aarch64-linux-musl-gcc"
3+
rustflags = ["-C", "target-feature=-crt-static"]

.github/workflows/CI.yml

Lines changed: 317 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,317 @@
1+
name: CI
2+
env:
3+
DEBUG: napi:*
4+
APP_NAME: doctor
5+
MACOSX_DEPLOYMENT_TARGET: '10.13'
6+
'on':
7+
push:
8+
branches:
9+
- main
10+
tags-ignore:
11+
- '**'
12+
paths-ignore:
13+
- '**/*.md'
14+
- LICENSE
15+
- '**/*.gitignore'
16+
- .editorconfig
17+
- docs/**
18+
pull_request: null
19+
jobs:
20+
build:
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
settings:
25+
- host: macos-latest
26+
target: x86_64-apple-darwin
27+
build: |
28+
yarn build
29+
strip -x *.node
30+
- host: windows-latest
31+
build: yarn build
32+
target: x86_64-pc-windows-msvc
33+
- host: windows-latest
34+
build: |
35+
yarn build --target i686-pc-windows-msvc
36+
yarn test
37+
target: i686-pc-windows-msvc
38+
- host: ubuntu-latest
39+
target: x86_64-unknown-linux-gnu
40+
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
41+
build: |-
42+
set -e &&
43+
yarn build --target x86_64-unknown-linux-gnu &&
44+
strip *.node
45+
- host: macos-latest
46+
target: aarch64-apple-darwin
47+
build: |
48+
yarn build --target aarch64-apple-darwin
49+
strip -x *.node
50+
- host: ubuntu-latest
51+
target: aarch64-unknown-linux-gnu
52+
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
53+
build: |-
54+
set -e &&
55+
yarn build --target aarch64-unknown-linux-gnu &&
56+
aarch64-unknown-linux-gnu-strip *.node
57+
- host: ubuntu-latest
58+
target: aarch64-unknown-linux-musl
59+
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
60+
build: |-
61+
set -e &&
62+
rustup target add aarch64-unknown-linux-musl &&
63+
yarn build --target aarch64-unknown-linux-musl &&
64+
/aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node
65+
- host: windows-latest
66+
target: aarch64-pc-windows-msvc
67+
build: yarn build --target aarch64-pc-windows-msvc
68+
name: stable - ${{ matrix.settings.target }} - node@18
69+
runs-on: ${{ matrix.settings.host }}
70+
steps:
71+
- uses: actions/checkout@v3
72+
- name: Setup node
73+
uses: actions/setup-node@v3
74+
if: ${{ !matrix.settings.docker }}
75+
with:
76+
node-version: 18
77+
check-latest: true
78+
cache: yarn
79+
- name: Install
80+
uses: dtolnay/rust-toolchain@stable
81+
if: ${{ !matrix.settings.docker }}
82+
with:
83+
toolchain: stable
84+
targets: ${{ matrix.settings.target }}
85+
- name: Cache cargo
86+
uses: actions/cache@v3
87+
with:
88+
path: |
89+
~/.cargo/registry/index/
90+
~/.cargo/registry/cache/
91+
~/.cargo/git/db/
92+
.cargo-cache
93+
target/
94+
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
95+
- uses: goto-bus-stop/setup-zig@v2
96+
if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' }}
97+
with:
98+
version: 0.10.1
99+
- name: Setup toolchain
100+
run: ${{ matrix.settings.setup }}
101+
if: ${{ matrix.settings.setup }}
102+
shell: bash
103+
- name: Setup node x86
104+
if: matrix.settings.target == 'i686-pc-windows-msvc'
105+
run: yarn config set supportedArchitectures.cpu "ia32"
106+
shell: bash
107+
- name: Install dependencies
108+
run: yarn install
109+
- name: Setup node x86
110+
uses: actions/setup-node@v3
111+
if: matrix.settings.target == 'i686-pc-windows-msvc'
112+
with:
113+
node-version: 18
114+
check-latest: true
115+
cache: yarn
116+
architecture: x86
117+
- name: Build in docker
118+
uses: addnab/docker-run-action@v3
119+
if: ${{ matrix.settings.docker }}
120+
with:
121+
image: ${{ matrix.settings.docker }}
122+
options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build'
123+
run: ${{ matrix.settings.build }}
124+
- name: Build
125+
run: ${{ matrix.settings.build }}
126+
if: ${{ !matrix.settings.docker }}
127+
shell: bash
128+
- name: Upload artifact
129+
uses: actions/upload-artifact@v3
130+
with:
131+
name: bindings-${{ matrix.settings.target }}
132+
path: ${{ env.APP_NAME }}.*.node
133+
if-no-files-found: error
134+
test-macOS-windows-binding:
135+
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
136+
needs:
137+
- build
138+
strategy:
139+
fail-fast: false
140+
matrix:
141+
settings:
142+
- host: windows-latest
143+
target: x86_64-pc-windows-msvc
144+
node:
145+
- '14'
146+
- '16'
147+
- '18'
148+
runs-on: ${{ matrix.settings.host }}
149+
steps:
150+
- uses: actions/checkout@v3
151+
- name: Setup node
152+
uses: actions/setup-node@v3
153+
with:
154+
node-version: ${{ matrix.node }}
155+
check-latest: true
156+
cache: yarn
157+
- name: Install dependencies
158+
run: yarn install
159+
- name: Download artifacts
160+
uses: actions/download-artifact@v3
161+
with:
162+
name: bindings-${{ matrix.settings.target }}
163+
path: .
164+
- name: List packages
165+
run: ls -R .
166+
shell: bash
167+
- name: Test bindings
168+
run: yarn test
169+
test-linux-x64-gnu-binding:
170+
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
171+
needs:
172+
- build
173+
strategy:
174+
fail-fast: false
175+
matrix:
176+
node:
177+
- '14'
178+
- '16'
179+
- '18'
180+
runs-on: ubuntu-latest
181+
steps:
182+
- uses: actions/checkout@v3
183+
- name: Setup node
184+
uses: actions/setup-node@v3
185+
with:
186+
node-version: ${{ matrix.node }}
187+
check-latest: true
188+
cache: yarn
189+
- name: Install dependencies
190+
run: yarn install
191+
- name: Download artifacts
192+
uses: actions/download-artifact@v3
193+
with:
194+
name: bindings-x86_64-unknown-linux-gnu
195+
path: .
196+
- name: List packages
197+
run: ls -R .
198+
shell: bash
199+
- name: Test bindings
200+
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test
201+
test-linux-aarch64-gnu-binding:
202+
name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
203+
needs:
204+
- build
205+
strategy:
206+
fail-fast: false
207+
matrix:
208+
node:
209+
- '14'
210+
- '16'
211+
- '18'
212+
runs-on: ubuntu-latest
213+
steps:
214+
- uses: actions/checkout@v3
215+
- name: Download artifacts
216+
uses: actions/download-artifact@v3
217+
with:
218+
name: bindings-aarch64-unknown-linux-gnu
219+
path: .
220+
- name: List packages
221+
run: ls -R .
222+
shell: bash
223+
- name: Install dependencies
224+
run: |
225+
yarn config set supportedArchitectures.cpu "arm64"
226+
yarn config set supportedArchitectures.libc "glibc"
227+
yarn install
228+
- name: Set up QEMU
229+
uses: docker/setup-qemu-action@v2
230+
with:
231+
platforms: arm64
232+
- run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
233+
- name: Setup and run tests
234+
uses: addnab/docker-run-action@v3
235+
with:
236+
image: node:${{ matrix.node }}-slim
237+
options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
238+
run: |
239+
set -e
240+
yarn test
241+
ls -la
242+
test-linux-aarch64-musl-binding:
243+
name: Test bindings on aarch64-unknown-linux-musl - node@${{ matrix.node }}
244+
needs:
245+
- build
246+
runs-on: ubuntu-latest
247+
steps:
248+
- uses: actions/checkout@v3
249+
- name: Download artifacts
250+
uses: actions/download-artifact@v3
251+
with:
252+
name: bindings-aarch64-unknown-linux-musl
253+
path: .
254+
- name: List packages
255+
run: ls -R .
256+
shell: bash
257+
- name: Install dependencies
258+
run: |
259+
yarn config set supportedArchitectures.cpu "arm64"
260+
yarn config set supportedArchitectures.libc "musl"
261+
yarn install
262+
- name: Set up QEMU
263+
uses: docker/setup-qemu-action@v2
264+
with:
265+
platforms: arm64
266+
- run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
267+
- name: Setup and run tests
268+
uses: addnab/docker-run-action@v3
269+
with:
270+
image: node:lts-alpine
271+
options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
272+
run: |
273+
set -e
274+
yarn test
275+
publish:
276+
name: Publish
277+
runs-on: ubuntu-latest
278+
needs:
279+
- test-macOS-windows-binding
280+
- test-linux-x64-gnu-binding
281+
- test-linux-aarch64-gnu-binding
282+
- test-linux-aarch64-musl-binding
283+
steps:
284+
- uses: actions/checkout@v3
285+
- name: Setup node
286+
uses: actions/setup-node@v3
287+
with:
288+
node-version: 18
289+
check-latest: true
290+
cache: yarn
291+
- name: Install dependencies
292+
run: yarn install
293+
- name: Download all artifacts
294+
uses: actions/download-artifact@v3
295+
with:
296+
path: artifacts
297+
- name: Move artifacts
298+
run: yarn artifacts
299+
- name: List packages
300+
run: ls -R ./npm
301+
shell: bash
302+
- name: Publish
303+
run: |
304+
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
305+
then
306+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
307+
npm publish --access public
308+
elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
309+
then
310+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
311+
npm publish --tag next --access public
312+
else
313+
echo "Not a release, skipping publish"
314+
fi
315+
env:
316+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
317+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)