Skip to content

use napi-rs #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ updates:
cargo:
patterns:
- "*"
- package-ecosystem: "npm" # also supports yarn
directory: "/"
schedule:
interval: "weekly"
groups:
npm:
patterns:
- "*"
34 changes: 31 additions & 3 deletions .github/workflows/bump_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
from pathlib import Path
import sys
import subprocess
import re

VER_PATTERN = re.compile(
Expand All @@ -12,6 +12,7 @@

class Updater:
component: str = "patch"
new_version: str = "0.0.0"

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


Expand All @@ -46,9 +48,35 @@ def main():
doc = cargo_path.read_text(encoding="utf-8")
doc = VER_PATTERN.sub(Updater.replace, doc)
cargo_path.write_text(doc, encoding="utf-8", newline="\n")
subprocess.run(["cargo", "update", "--workspace"], check=True)
print("Updated version in Cargo.toml")
return 0
subprocess.run(
[
"yarn",
"version",
"--new-version",
Updater.new_version,
"--no-git-tag-version",
],
cwd="node-binding",
check=True,
)
print("Updated version in node-binding/**package.json")
tag = "v" + Updater.new_version
subprocess.run(["git", "add", "--all"], check=True)
subprocess.run(["git", "commit", "-m", f"bump version to {tag}"], check=True)
try:
subprocess.run(["git", "push"], check=True)
except subprocess.CalledProcessError as exc:
raise RuntimeError("Failed to push commit for version bump") from exc
print("Pushed commit to 'bump version to", tag, "'")
try:
subprocess.run(["git", "tag", tag], check=True)
except subprocess.CalledProcessError as exc:
raise RuntimeError("Failed to create tag for commit") from exc
print("Created tag", tag)
print(f"Use 'git push origin refs/tags/{tag}' to publish a release")


if __name__ == "__main__":
sys.exit(main())
main()
220 changes: 220 additions & 0 deletions .github/workflows/node-js-packaging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
name: node-js builds
env:
DEBUG: napi:*
APP_NAME: cpp-linter
MACOSX_DEPLOYMENT_TARGET: '10.13'
permissions:
contents: write
id-token: write
on:
push:
branches:
- main
tags:
- '*'
paths-ignore:
- '**/*.md'
- LICENSE
- '**/*.gitignore'
- .editorconfig
- docs/**
pull_request:
branches:
- main
jobs:
build:
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
target: x86_64-apple-darwin
build: yarn build --target x86_64-apple-darwin --features openssl-vendored
- host: windows-latest
build: yarn build --target x86_64-pc-windows-msvc
target: x86_64-pc-windows-msvc
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
build: yarn build --target x86_64-unknown-linux-gnu --features openssl-vendored
name: stable - ${{ matrix.settings.target }} - node@20
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
if: ${{ !matrix.settings.docker }}
with:
node-version: 20
cache: yarn
- name: Install
uses: dtolnay/rust-toolchain@stable
if: ${{ !matrix.settings.docker }}
with:
toolchain: stable
targets: ${{ matrix.settings.target }}
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
.cargo-cache
target/
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
- uses: goto-bus-stop/setup-zig@v2
if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' || matrix.settings.target == 'armv7-unknown-linux-musleabihf' }}
with:
version: 0.13.0
- name: Setup toolchain
run: ${{ matrix.settings.setup }}
if: ${{ matrix.settings.setup }}
shell: bash
- name: Setup node x86
working-directory: node-binding
if: matrix.settings.target == 'i686-pc-windows-msvc'
run: yarn config set supportedArchitectures.cpu "ia32"
shell: bash
- name: Install dependencies
working-directory: node-binding
run: yarn install
- name: Setup node x86
uses: actions/setup-node@v4
if: matrix.settings.target == 'i686-pc-windows-msvc'
with:
node-version: 20
cache: yarn
architecture: x86
- name: Build in docker
uses: addnab/docker-run-action@v3
if: ${{ matrix.settings.docker }}
with:
image: ${{ matrix.settings.docker }}
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
run: ${{ matrix.settings.build }}
- name: Build
run: ${{ matrix.settings.build }}
if: ${{ !matrix.settings.docker }}
working-directory: node-binding
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: bindings-${{ matrix.settings.target }}
path: node-binding/${{ env.APP_NAME }}.*.node
if-no-files-found: error
test-macOS-windows-binding:
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
needs:
- build
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
target: x86_64-apple-darwin
- host: windows-latest
target: x86_64-pc-windows-msvc
node:
- '18'
- '20'
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: yarn
architecture: x64
- name: Install dependencies
run: yarn install
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bindings-${{ matrix.settings.target }}
path: node-binding
- name: List packages
run: ls -R .
working-directory: node-binding
shell: bash
- name: Test bindings
run: yarn test
test-linux-x64-gnu-binding:
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
needs:
- build
strategy:
fail-fast: false
matrix:
node:
- '18'
- '20'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: yarn
- name: Install dependencies
run: yarn install
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bindings-x86_64-unknown-linux-gnu
path: node-binding
- name: List packages
run: ls -R .
working-directory: node-binding
shell: bash
- name: Test bindings
run: >-
docker run --rm
-v $(pwd):/build
-w /build
node:${{ matrix.node }}-slim
yarn test
publish:
name: Publish
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs:
- test-macOS-windows-binding
- test-linux-x64-gnu-binding
steps:
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
- name: Install dependencies
run: yarn install
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: node-binding/artifacts
- name: Move artifacts
working-directory: node-binding
run: yarn artifacts
- name: List packages
run: ls -R ./npm
working-directory: node-binding
shell: bash
- name: Publish
working-directory: node-binding
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
npm publish --access public --provenance true ${{ contains(github.ref_name, '-rc') && '--tag next' || '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 0 additions & 2 deletions .github/workflows/python-packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
branches:
- main
- master
workflow_dispatch:

permissions:
Expand Down
Loading
Loading