Skip to content

Commit 4e003f5

Browse files
committed
first commit
0 parents  commit 4e003f5

File tree

22 files changed

+3721
-0
lines changed

22 files changed

+3721
-0
lines changed

.github/workflows/CI.yml

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
name: CI
2+
3+
env:
4+
DEBUG: napi:*
5+
APP_NAME: python-node
6+
MACOSX_DEPLOYMENT_TARGET: '10.13'
7+
8+
permissions:
9+
contents: write
10+
id-token: write
11+
12+
on:
13+
push:
14+
branches:
15+
- main
16+
tags-ignore:
17+
- '**'
18+
paths-ignore:
19+
- '**/*.md'
20+
- LICENSE
21+
- '**/*.gitignore'
22+
- .editorconfig
23+
- docs/**
24+
pull_request:
25+
26+
jobs:
27+
build:
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
settings:
32+
- host: macos-latest
33+
target: x86_64-apple-darwin
34+
build: pnpm run build --target x86_64-apple-darwin
35+
- host: ubuntu-latest
36+
target: x86_64-unknown-linux-gnu
37+
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
38+
build: pnpm run build --target x86_64-unknown-linux-gnu
39+
- host: macos-latest
40+
target: aarch64-apple-darwin
41+
build: pnpm run build --target aarch64-apple-darwin
42+
name: stable - ${{ matrix.settings.target }} - node@20
43+
runs-on: ${{ matrix.settings.host }}
44+
steps:
45+
- uses: actions/checkout@v4
46+
- uses: webfactory/ssh-agent@v0.9.0
47+
with:
48+
ssh-private-key: ${{ secrets.HTTP_HANDLER_ACCESS_TOKEN }}
49+
- uses: pnpm/action-setup@v4
50+
with:
51+
version: latest
52+
- uses: actions/setup-node@v4
53+
if: ${{ !matrix.settings.docker }}
54+
with:
55+
node-version: 20
56+
- name: Install
57+
uses: dtolnay/rust-toolchain@stable
58+
if: ${{ !matrix.settings.docker }}
59+
with:
60+
toolchain: stable
61+
targets: ${{ matrix.settings.target }}
62+
- name: Cache cargo
63+
uses: actions/cache@v4
64+
with:
65+
path: |
66+
~/.cargo/registry/index/
67+
~/.cargo/registry/cache/
68+
~/.cargo/git/db/
69+
.cargo-cache
70+
target/
71+
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
72+
- uses: goto-bus-stop/setup-zig@v2
73+
if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' || matrix.settings.target == 'armv7-unknown-linux-musleabihf' }}
74+
with:
75+
version: 0.13.0
76+
- name: Setup toolchain
77+
run: ${{ matrix.settings.setup }}
78+
if: ${{ matrix.settings.setup }}
79+
shell: bash
80+
- name: Install dependencies
81+
run: pnpm install
82+
- name: Build in docker
83+
uses: addnab/docker-run-action@v3
84+
if: ${{ matrix.settings.docker }}
85+
with:
86+
image: ${{ matrix.settings.docker }}
87+
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'
88+
run: |
89+
set -x
90+
91+
# Install apt dependencies
92+
apt-get update -y
93+
apt-get install -y openssh-client
94+
95+
# Setup pnpm
96+
corepack disable
97+
npm i -gf pnpm
98+
99+
# Set up SSH key (to checkout private repos with cargo)
100+
mkdir -p ~/.ssh
101+
chmod -R 400 ~/.ssh
102+
touch ~/.ssh/config ~/.ssh/known_hosts
103+
eval `ssh-agent -s`
104+
echo "${{ secrets.HTTP_HANDLER_ACCESS_TOKEN }}" | tr -d '\r' | ssh-add -
105+
ssh-add -l
106+
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
107+
108+
${{ matrix.settings.build }}
109+
- name: Build
110+
run: ${{ matrix.settings.build }}
111+
if: ${{ !matrix.settings.docker }}
112+
shell: bash
113+
- name: Upload artifact
114+
uses: actions/upload-artifact@v4
115+
with:
116+
name: bindings-${{ matrix.settings.target }}
117+
path: |
118+
${{ env.APP_NAME }}.*.node
119+
index.d.ts
120+
index.js
121+
if-no-files-found: error
122+
123+
test-macOS-windows-binding:
124+
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
125+
needs:
126+
- build
127+
strategy:
128+
fail-fast: false
129+
matrix:
130+
settings:
131+
- host: macos-latest
132+
target: x86_64-apple-darwin
133+
node:
134+
- '18'
135+
- '20'
136+
runs-on: ${{ matrix.settings.host }}
137+
steps:
138+
- uses: actions/checkout@v4
139+
- uses: webfactory/ssh-agent@v0.9.0
140+
with:
141+
ssh-private-key: ${{ secrets.HTTP_HANDLER_ACCESS_TOKEN }}
142+
- uses: pnpm/action-setup@v4
143+
with:
144+
version: latest
145+
- uses: actions/setup-node@v4
146+
with:
147+
node-version: ${{ matrix.node }}
148+
cache: pnpm
149+
architecture: x64
150+
- run: pnpm install
151+
- uses: actions/download-artifact@v4
152+
with:
153+
name: bindings-${{ matrix.settings.target }}
154+
path: .
155+
- name: List packages
156+
run: ls -R .
157+
shell: bash
158+
- run: cargo test
159+
- run: pnpm test
160+
161+
test-linux-binding:
162+
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
163+
needs:
164+
- build
165+
strategy:
166+
fail-fast: false
167+
matrix:
168+
settings:
169+
- host: ubuntu-22.04
170+
target: x86_64-unknown-linux-gnu
171+
# Not supported yet.
172+
# - host: ubuntu-22.04
173+
# target: x86_64-unknown-linux-musl
174+
# Not supported yet, ubuntu-24.04-arm runner requires repo is public
175+
# - host: ubuntu-22.04-arm
176+
# target: aarch64-unknown-linux-gnu
177+
# - host: ubuntu-22.04-arm
178+
# target: aarch64-unknown-linux-musl
179+
node:
180+
- '18'
181+
- '20'
182+
runs-on: ${{ matrix.settings.host }}
183+
steps:
184+
- uses: actions/checkout@v4
185+
- uses: pnpm/action-setup@v4
186+
with:
187+
version: latest
188+
- name: Setup node
189+
uses: actions/setup-node@v4
190+
with:
191+
node-version: ${{ matrix.node }}
192+
cache: pnpm
193+
- name: Install dependencies
194+
run: pnpm install
195+
- uses: actions/download-artifact@v4
196+
with:
197+
name: bindings-${{ matrix.settings.target }}
198+
path: .
199+
- name: List packages
200+
run: ls -R .
201+
shell: bash
202+
- name: Output docker params
203+
id: docker
204+
run: |
205+
node -e "
206+
if ('${{ matrix.settings.target }}'.startsWith('aarch64')) {
207+
console.log('PLATFORM=linux/arm64')
208+
} else if ('${{ matrix.settings.target }}'.startsWith('armv7')) {
209+
console.log('PLATFORM=linux/arm/v7')
210+
} else {
211+
console.log('PLATFORM=linux/amd64')
212+
}
213+
" >> $GITHUB_OUTPUT
214+
node -e "
215+
if ('${{ matrix.settings.target }}'.endsWith('-musl')) {
216+
console.log('IMAGE=node:${{ matrix.node }}-alpine')
217+
} else {
218+
console.log('IMAGE=node:${{ matrix.node }}-slim')
219+
}
220+
" >> $GITHUB_OUTPUT
221+
echo "PNPM_STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
222+
- name: Test crates
223+
uses: addnab/docker-run-action@v3
224+
with:
225+
image: ${{ steps.docker.outputs.IMAGE }}
226+
options: -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }} --platform ${{ steps.docker.outputs.PLATFORM }}
227+
run: |
228+
set -x
229+
230+
# Install apt dependencies
231+
apt-get update -y
232+
apt-get install -y openssh-client curl
233+
234+
# Install rust toolchain
235+
curl https://sh.rustup.rs -sSf | bash -s -- -y -t ${{ matrix.settings.target }}
236+
source "$HOME/.cargo/env"
237+
238+
# Set up SSH key (to checkout private repos with cargo)
239+
mkdir -p ~/.ssh
240+
chmod -R 400 ~/.ssh
241+
touch ~/.ssh/config ~/.ssh/known_hosts
242+
eval `ssh-agent -s`
243+
echo "${{ secrets.HTTP_HANDLER_ACCESS_TOKEN }}" | tr -d '\r' | ssh-add -
244+
ssh-add -l
245+
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
246+
247+
cargo test --target ${{ matrix.settings.target }}
248+
- name: Test bindings
249+
uses: addnab/docker-run-action@v3
250+
with:
251+
image: ${{ steps.docker.outputs.IMAGE }}
252+
options: -v ${{ steps.docker.outputs.PNPM_STORE_PATH }}:${{ steps.docker.outputs.PNPM_STORE_PATH }} -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }} --platform ${{ steps.docker.outputs.PLATFORM }}
253+
run: |
254+
corepack disable
255+
npm i -gf pnpm
256+
pnpm test
257+
258+
publish:
259+
name: Publish
260+
runs-on: ubuntu-latest
261+
needs:
262+
- test-macOS-windows-binding
263+
- test-linux-binding
264+
steps:
265+
- uses: actions/checkout@v4
266+
- uses: pnpm/action-setup@v4
267+
with:
268+
version: latest
269+
- uses: actions/setup-node@v4
270+
with:
271+
node-version: 20
272+
cache: pnpm
273+
- name: Install dependencies
274+
run: pnpm install
275+
- name: Download all artifacts
276+
uses: actions/download-artifact@v4
277+
with:
278+
path: artifacts
279+
- name: Move artifacts
280+
run: pnpm artifacts
281+
- name: List packages
282+
run: ls -R ./npm
283+
shell: bash
284+
- name: Publish
285+
if: contains(github.ref, 'main')
286+
run: |
287+
npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
288+
npm config set scope "@platformatic"
289+
# npm config set provenance true
290+
if git log -1 --pretty=%B | grep "^v\?[0-9]\+\.[0-9]\+\.[0-9]\+";
291+
then
292+
npm publish --access public --dry-run
293+
elif git log -1 --pretty=%B | grep "^v\?[0-9]\+\.[0-9]\+\.[0-9]\+-\.+";
294+
then
295+
npm publish --tag next --access public --dry-run
296+
else
297+
echo "Not a release, skipping publish"
298+
fi
299+
env:
300+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
301+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/lint.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Lint
2+
3+
'on':
4+
push:
5+
branches:
6+
- main
7+
tags-ignore:
8+
- '**'
9+
paths-ignore:
10+
- '**/*.md'
11+
- LICENSE
12+
- '**/*.gitignore'
13+
- .editorconfig
14+
- docs/**
15+
pull_request: null
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}-lint
19+
cancel-in-progress: true
20+
21+
jobs:
22+
lint:
23+
name: Lint
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: setup pnpm
28+
uses: pnpm/action-setup@v4
29+
with:
30+
version: 10
31+
- name: Setup node
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: 22
35+
cache: pnpm
36+
37+
- name: Install
38+
uses: dtolnay/rust-toolchain@stable
39+
with:
40+
components: clippy, rustfmt
41+
42+
- name: Install dependencies
43+
run: pnpm install
44+
45+
- name: ESLint
46+
run: pnpm lint
47+
48+
- name: Cargo fmt
49+
run: cargo fmt -- --check
50+
51+
- name: Clippy
52+
run: cargo clippy

0 commit comments

Comments
 (0)