Files
zen/.github/workflows/node.yaml

327 lines
10 KiB
YAML

name: NodeJS
env:
WORKING_DIRECTORY: bindings/nodejs
DEBUG: 'napi:*'
MACOSX_DEPLOYMENT_TARGET: '10.13'
NODE_OPTIONS: '--max-old-space-size=3072'
CARGO_UNSTABLE_TARGET_APPLIES_TO_HOST: true
CARGO_TARGET_APPLIES_TO_HOST: false
on:
pull_request:
paths:
- 'bindings/nodejs/**'
- 'core/**'
- 'test-data/**'
- '.github/workflows/node.yaml'
push:
tags:
- 'nodejs-v*'
permissions:
contents: write
id-token: write
jobs:
build:
strategy:
fail-fast: false
matrix:
settings:
- host: windows-latest
target: 'x86_64-pc-windows-msvc'
build: |
yarn build -- --target x86_64-pc-windows-msvc -- --locked
- host: macos-15-intel
target: 'x86_64-apple-darwin'
build: |
rustup target add x86_64-apple-darwin
yarn build -- --target x86_64-apple-darwin -- --locked
strip -x ./*.node
- host: macos-latest
target: 'aarch64-apple-darwin'
build: |
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*;
export CC=$(xcrun -f clang);
export CXX=$(xcrun -f clang++);
SYSROOT=$(xcrun --sdk macosx --show-sdk-path);
export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT";
yarn build -- --target aarch64-apple-darwin -- --locked
strip -x ./*.node
- host: ubuntu-latest
target: 'x86_64-unknown-linux-gnu'
zig: true
build: |
set -e
rustup target add x86_64-unknown-linux-gnu
mkdir -p ../../target
ln -sfn x86_64-unknown-linux-gnu ../../target/x86_64-unknown-linux-gnu.$GLIBC_VERSION
yarn build -- --target x86_64-unknown-linux-gnu.$GLIBC_VERSION --cross-compile -- --locked
mv -f zen-engine.linux-x64-gnu.$GLIBC_VERSION.node zen-engine.linux-x64-gnu.node
strip zen-engine.linux-x64-gnu.node
- host: ubuntu-latest
target: 'aarch64-unknown-linux-gnu'
zig: true
build: |
set -e
rustup target add aarch64-unknown-linux-gnu
mkdir -p ../../target
ln -sfn aarch64-unknown-linux-gnu ../../target/aarch64-unknown-linux-gnu.$GLIBC_VERSION
yarn build -- --target aarch64-unknown-linux-gnu.$GLIBC_VERSION --cross-compile -- --locked
mv -f zen-engine.linux-arm64-gnu.$GLIBC_VERSION.node zen-engine.linux-arm64-gnu.node
- host: ubuntu-latest
target: 'x86_64-unknown-linux-musl'
zig: true
build: |
set -e
rustup target add x86_64-unknown-linux-musl
yarn build -- --target x86_64-unknown-linux-musl --cross-compile -- --locked
strip ./*.node
- host: ubuntu-latest
target: 'aarch64-unknown-linux-musl'
zig: true
build: |
set -e
rustup target add aarch64-unknown-linux-musl
yarn build -- --target aarch64-unknown-linux-musl --cross-compile -- --locked
- host: ubuntu-latest
target: 'wasm32-wasip1-threads'
setup: |
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-27/wasi-sdk-27.0-x86_64-linux.tar.gz
tar -xvf wasi-sdk-27.0-x86_64-linux.tar.gz
build: |
set -e
export WASI_SDK_PATH="$(pwd)/wasi-sdk-27.0-x86_64-linux"
export CMAKE_BUILD_PARALLEL_LEVEL=2
export TARGET_CXXFLAGS="--target=wasm32-wasi-threads --sysroot=$(pwd)/wasi-sdk-27.0-x86_64-linux/share/wasi-sysroot -pthread -mllvm -wasm-enable-sjlj -lsetjmp"
export TARGET_CFLAGS="$TARGET_CXXFLAGS"
yarn build -- --target wasm32-wasip1-threads -- --locked
name: stable - ${{ matrix.settings.target }} - node@22
runs-on: ${{ matrix.settings.host }}
defaults:
run:
working-directory: ${{ env.WORKING_DIRECTORY }}
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 22
check-latest: true
cache: yarn
cache-dependency-path: 'bindings/nodejs/yarn.lock'
- name: Install
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: ${{ matrix.settings.target }}
- name: Rust cache + sccache (+ zig for linux legs)
uses: ./.github/actions/setup-rust
with:
shared-key: nodejs-${{ matrix.settings.target }}
key: ${{ matrix.settings.target }}
zig: ${{ matrix.settings.zig }}
sccache-bucket: ${{ secrets.SCCACHE_S3_BUCKET }}
sccache-region: ${{ secrets.SCCACHE_AWS_REGION }}
sccache-role-arn: ${{ secrets.SCCACHE_AWS_ROLE_ARN }}
- name: Setup toolchain
run: ${{ matrix.settings.setup }}
if: ${{ matrix.settings.setup }}
shell: bash
- name: 'Install dependencies'
run: yarn install --immutable --mode=skip-build
- name: 'Build'
run: ${{ matrix.settings.build }}
shell: bash
- name: 'Check'
run: ls -la
shell: bash
- name: Upload artifact ${{ matrix.settings.target }}
if: ${{ matrix.settings.target != 'wasm32-wasip1-threads' }}
uses: actions/upload-artifact@v4
with:
name: bindings-${{ matrix.settings.target }}
path: bindings/nodejs/*.node
if-no-files-found: error
- name: Upload artifact ${{ matrix.settings.target }}
if: ${{ matrix.settings.target == 'wasm32-wasip1-threads' }}
uses: actions/upload-artifact@v4
with:
name: bindings-wasm32-wasi
if-no-files-found: error
path: |
bindings/nodejs/*.wasm
bindings/nodejs/zen-engine.wasi*
bindings/nodejs/wasi-worker*
test:
name: Test ${{ matrix.settings.target }} - node@${{ matrix.node }}
needs:
- build
defaults:
run:
working-directory: ${{ env.WORKING_DIRECTORY }}
strategy:
fail-fast: false
matrix:
node: [ '20', '22' ]
settings:
# Native runners
- host: macos-15-intel
target: 'x86_64-apple-darwin'
- host: macos-latest
target: 'aarch64-apple-darwin'
- host: windows-latest
target: 'x86_64-pc-windows-msvc'
# Linux: run inside the matching libc container; arm adds QEMU
- host: ubuntu-latest
target: 'x86_64-unknown-linux-gnu'
image: 'node:{0}-slim'
- host: ubuntu-latest
target: 'x86_64-unknown-linux-musl'
image: 'node:{0}-alpine'
- host: ubuntu-latest
target: 'aarch64-unknown-linux-musl'
image: 'node:{0}-alpine'
arm: true
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
check-latest: true
cache: yarn
cache-dependency-path: 'bindings/nodejs/yarn.lock'
- name: Set up QEMU
if: ${{ matrix.settings.arm }}
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- if: ${{ matrix.settings.arm }}
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- name: Install dependencies (arm64/musl)
if: ${{ matrix.settings.arm }}
run: |
yarn config set supportedArchitectures.cpu "arm64"
yarn config set supportedArchitectures.libc "musl"
yarn install --immutable --mode=skip-build
- name: Install dependencies
if: ${{ !matrix.settings.arm }}
run: yarn install --immutable --mode=skip-build
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bindings-${{ matrix.settings.target }}
path: artifacts
- name: Create dirs
run: yarn createNpmDirs
shell: bash
- name: Move artifacts
run: yarn artifacts
shell: bash
- name: Test bindings (native)
if: ${{ !matrix.settings.image }}
run: |
yarn install
yarn link
yarn test
- name: Test bindings (docker)
if: ${{ matrix.settings.image }}
uses: stefan-gorules/docker-run-action@v1
with:
image: ${{ format(matrix.settings.image, matrix.node) }}
options: ${{ matrix.settings.arm && format('--platform linux/arm64 -v {0}:/workspace', github.workspace) || format('-v {0}:/workspace', github.workspace) }}
run: |
cd workspace/bindings/nodejs
yarn install
yarn link
yarn test
release:
name: Release
runs-on: ubuntu-latest
environment: release
# Publishes only on the release-please GitHub Release for the nodejs component.
if: "github.ref_type == 'tag'"
defaults:
run:
working-directory: ${{ env.WORKING_DIRECTORY }}
needs:
- test
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 22
check-latest: true
cache: yarn
cache-dependency-path: 'bindings/nodejs/yarn.lock'
registry-url: 'https://registry.npmjs.org'
# Organisation
scope: '@gorules'
- name: 'Install dependencies'
run: yarn install --immutable --mode=skip-build
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: List all artifacts
run: ls -la ../../artifacts
- name: Copy LICENSE
run: cp ../../LICENSE .
- name: Create dirs
run: yarn createNpmDirs
shell: bash
- name: Move artifacts
run: yarn artifacts
- name: List folder
run: ls ./
shell: bash
- name: Lerna publish
run: yarn lerna publish from-package --dist-tag ${{ contains(github.ref, '-beta') && 'beta' || 'latest' }} --no-verify-access --yes
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}