Skip to content

Commit 937a567

Browse files
authored
use napi-rs (#39)
* use napi-rs make a yarn workspace update cargo lock * add npm to dependabot config * prepare release workflow
1 parent 25c3951 commit 937a567

29 files changed

+2629
-210
lines changed

.github/dependabot.yml

+8
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@ updates:
3131
cargo:
3232
patterns:
3333
- "*"
34+
- package-ecosystem: "npm" # also supports yarn
35+
directory: "/"
36+
schedule:
37+
interval: "weekly"
38+
groups:
39+
npm:
40+
patterns:
41+
- "*"

.github/workflows/bump_version.py

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import argparse
22
from pathlib import Path
3-
import sys
3+
import subprocess
44
import re
55

66
VER_PATTERN = re.compile(
@@ -12,6 +12,7 @@
1212

1313
class Updater:
1414
component: str = "patch"
15+
new_version: str = "0.0.0"
1516

1617
@staticmethod
1718
def replace(match: re.Match[str]) -> str:
@@ -35,6 +36,7 @@ def replace(match: re.Match[str]) -> str:
3536
rc_str = f"-rc{ver[3]}" if ver[3] > 0 else ""
3637
new_version += rc_str
3738
print("new version:", new_version)
39+
Updater.new_version = new_version
3840
return VER_REPLACE % (tuple(ver[:3]) + (rc_str,))
3941

4042

@@ -46,9 +48,35 @@ def main():
4648
doc = cargo_path.read_text(encoding="utf-8")
4749
doc = VER_PATTERN.sub(Updater.replace, doc)
4850
cargo_path.write_text(doc, encoding="utf-8", newline="\n")
51+
subprocess.run(["cargo", "update", "--workspace"], check=True)
4952
print("Updated version in Cargo.toml")
50-
return 0
53+
subprocess.run(
54+
[
55+
"yarn",
56+
"version",
57+
"--new-version",
58+
Updater.new_version,
59+
"--no-git-tag-version",
60+
],
61+
cwd="node-binding",
62+
check=True,
63+
)
64+
print("Updated version in node-binding/**package.json")
65+
tag = "v" + Updater.new_version
66+
subprocess.run(["git", "add", "--all"], check=True)
67+
subprocess.run(["git", "commit", "-m", f"bump version to {tag}"], check=True)
68+
try:
69+
subprocess.run(["git", "push"], check=True)
70+
except subprocess.CalledProcessError as exc:
71+
raise RuntimeError("Failed to push commit for version bump") from exc
72+
print("Pushed commit to 'bump version to", tag, "'")
73+
try:
74+
subprocess.run(["git", "tag", tag], check=True)
75+
except subprocess.CalledProcessError as exc:
76+
raise RuntimeError("Failed to create tag for commit") from exc
77+
print("Created tag", tag)
78+
print(f"Use 'git push origin refs/tags/{tag}' to publish a release")
5179

5280

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

.github/workflows/python-packaging.yml

-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ on:
1616
push:
1717
branches:
1818
- main
19-
- master
2019
tags:
2120
- '*'
2221
pull_request:
2322
branches:
2423
- main
25-
- master
2624
workflow_dispatch:
2725

2826
permissions:

0 commit comments

Comments
 (0)