test: Perf test #105
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
env: | |
DEBUG: napi:* | |
MACOSX_DEPLOYMENT_TARGET: '10.13' | |
RUST_BACKTRACE: 1 | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- 'v*.*.*' | |
pull_request: | |
jobs: | |
# Builds native Node.js bindings for each target platform using napi-rs. | |
# The build artifacts are uploaded and used by the test job. | |
build: | |
name: Build - ${{ matrix.target }} | |
if: "!contains(github.event.head_commit.message, 'skip ci')" | |
strategy: | |
fail-fast: false | |
matrix: | |
target: [aarch64-apple-darwin, x86_64-apple-darwin, x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, x86_64-pc-windows-msvc] | |
include: | |
- target: aarch64-apple-darwin | |
os: macos-latest | |
- target: x86_64-apple-darwin | |
os: macos-latest | |
- target: x86_64-unknown-linux-gnu | |
os: ubuntu-latest | |
- target: aarch64-unknown-linux-gnu | |
os: ubuntu-latest | |
- target: x86_64-pc-windows-msvc | |
os: windows-latest | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
- name: Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
cache: npm | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
toolchain: stable | |
targets: ${{ matrix.target }} | |
- name: Install Zig | |
uses: mlugg/setup-zig@v1 | |
if: ${{ runner.os == 'Linux' }} | |
- name: Cache NPM dependencies | |
uses: actions/cache@v4 | |
with: | |
path: node_modules | |
key: npm-cache-${{ matrix.target }}-node@18-${{ hashFiles('package-lock.json') }} | |
- name: Cache Rust dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target/ | |
key: rust-cache-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} | |
- name: Install dependencies | |
run: npm install | |
shell: bash | |
- name: Build | |
run: npx nx run @kevinmichaelchen/cel-typescript-core:build:native --target=${{ matrix.target }} | |
env: | |
USE_ZIG: ${{ runner.os == 'Linux' }} | |
shell: bash | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: bindings-${{ matrix.target }} | |
path: | | |
**/*.node | |
!node_modules/**/*.node | |
!target/**/*.node | |
if-no-files-found: error | |
retention-days: 1 | |
# Downloads the built native modules and runs the test suite on each platform | |
# to ensure the bindings work correctly across different architectures. | |
test: | |
name: Test - ${{ matrix.target }} | |
needs: | |
- build | |
strategy: | |
fail-fast: false | |
matrix: | |
target: [aarch64-apple-darwin, x86_64-apple-darwin, x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, x86_64-pc-windows-msvc] | |
include: | |
- target: aarch64-apple-darwin | |
os: macos-latest | |
- target: x86_64-apple-darwin | |
os: macos-latest | |
- target: x86_64-unknown-linux-gnu | |
os: ubuntu-latest | |
- target: aarch64-unknown-linux-gnu | |
os: ubuntu-latest | |
- target: x86_64-pc-windows-msvc | |
os: windows-latest | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
- name: Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
cache: npm | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: bindings-* | |
merge-multiple: true | |
- name: Copy binaries to src for testing | |
run: | | |
# Copy all .node files found in libs/core to libs/core/src | |
echo "Copying all .node binaries to libs/core/src/" | |
find "libs/core" -maxdepth 1 -name "*.node" -exec cp {} "libs/core/src/" \; | |
# Show what was copied | |
echo "Files in libs/core/src:" | |
find "libs/core/src" -type f -name "*.node" | sort | |
shell: bash | |
- name: Install dependencies | |
run: npm install | |
- name: Test | |
run: npm test | |
# Publishes the package to npm when a tag is pushed, or performs a dry-run during PRs. | |
publish: | |
name: ${{ github.event_name == 'pull_request' && '🔍 Publish (Dry Run)' || '📦 Publish' }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
id-token: write | |
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'pull_request' | |
needs: | |
- build | |
- test | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
- name: Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
cache: npm | |
registry-url: 'https://registry.npmjs.org' | |
- name: Install dependencies | |
run: npm install | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: bindings-* | |
merge-multiple: true | |
- name: Process artifacts and prepare packages | |
run: | | |
echo "Debug: Showing all downloaded artifacts:" | |
find . -type f -name "*.node" -ls | |
echo "\nEnsuring binaries exist in their respective package directories:" | |
# Make sure each package directory has exactly one binary | |
# Copy only if not already present in the target directory | |
if [ ! -f libs/darwin-arm64/cel-typescript.darwin-arm64.node ]; then | |
find . -path "./libs/darwin-arm64" -prune -o -name "cel-typescript.darwin-arm64.node" -exec cp {} libs/darwin-arm64/ \; | |
fi | |
if [ ! -f libs/darwin-x64/cel-typescript.darwin-x64.node ]; then | |
find . -path "./libs/darwin-x64" -prune -o -name "cel-typescript.darwin-x64.node" -exec cp {} libs/darwin-x64/ \; | |
fi | |
if [ ! -f libs/linux-x64-gnu/cel-typescript.linux-x64-gnu.node ]; then | |
find . -path "./libs/linux-x64-gnu" -prune -o -name "cel-typescript.linux-x64-gnu.node" -exec cp {} libs/linux-x64-gnu/ \; | |
fi | |
if [ ! -f libs/linux-arm64-gnu/cel-typescript.linux-arm64-gnu.node ]; then | |
find . -path "./libs/linux-arm64-gnu" -prune -o -name "cel-typescript.linux-arm64-gnu.node" -exec cp {} libs/linux-arm64-gnu/ \; | |
fi | |
if [ ! -f libs/win32-x64-msvc/cel-typescript.win32-x64-msvc.node ]; then | |
find . -path "./libs/win32-x64-msvc" -prune -o -name "cel-typescript.win32-x64-msvc.node" -exec cp {} libs/win32-x64-msvc/ \; | |
fi | |
# Verify each package directory has exactly one binary | |
darwin_arm64_count=$(find libs/darwin-arm64 -maxdepth 1 -name "cel-typescript.darwin-arm64.node" | wc -l) | |
darwin_x64_count=$(find libs/darwin-x64 -maxdepth 1 -name "cel-typescript.darwin-x64.node" | wc -l) | |
linux_x64_gnu_count=$(find libs/linux-x64-gnu -maxdepth 1 -name "cel-typescript.linux-x64-gnu.node" | wc -l) | |
linux_arm64_gnu_count=$(find libs/linux-arm64-gnu -maxdepth 1 -name "cel-typescript.linux-arm64-gnu.node" | wc -l) | |
win32_x64_msvc_count=$(find libs/win32-x64-msvc -maxdepth 1 -name "cel-typescript.win32-x64-msvc.node" | wc -l) | |
echo "\nVerifying binaries in package directories:" | |
echo "darwin-arm64: $darwin_arm64_count" | |
echo "darwin-x64: $darwin_x64_count" | |
echo "linux-x64-gnu: $linux_x64_gnu_count" | |
echo "linux-arm64-gnu: $linux_arm64_gnu_count" | |
echo "win32-x64-msvc: $win32_x64_msvc_count" | |
# Error if any platform is missing its binary | |
if [ "$darwin_arm64_count" -ne 1 ] || [ "$darwin_x64_count" -ne 1 ] || \ | |
[ "$linux_x64_gnu_count" -ne 1 ] || [ "$linux_arm64_gnu_count" -ne 1 ] || \ | |
[ "$win32_x64_msvc_count" -ne 1 ]; then | |
echo "Error: Each package directory should have exactly one binary" | |
exit 1 | |
fi | |
# Set version for all packages based on tag | |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then | |
VERSION=${GITHUB_REF#refs/tags/v} | |
echo "Setting version to $VERSION for all packages" | |
for pkg in libs/darwin-arm64 libs/darwin-x64 libs/linux-x64-gnu libs/linux-arm64-gnu libs/win32-x64-msvc; do | |
jq ".version = \"$VERSION\"" $pkg/package.json > tmp.json && mv tmp.json $pkg/package.json | |
done | |
# Set the core package version too | |
jq ".version = \"$VERSION\"" libs/core/package.json > tmp.json && mv tmp.json libs/core/package.json | |
# Update the optionalDependencies in the core package to use version numbers instead of file paths | |
node -e "const pkg = require('./libs/core/package.json'); \ | |
if (pkg.optionalDependencies) { \ | |
Object.keys(pkg.optionalDependencies).forEach(dep => { \ | |
pkg.optionalDependencies[dep] = '$VERSION'; \ | |
}); \ | |
require('fs').writeFileSync('./libs/core/package.json', JSON.stringify(pkg, null, 2)); \ | |
}" | |
else | |
echo "Not a tag push, skipping version update" | |
fi | |
- name: Build TypeScript | |
run: npm run build:ts | |
- name: Publish Core Package (Dry Run) | |
if: github.event_name == 'pull_request' | |
run: | | |
cd libs/core | |
npm pack --dry-run | |
- name: Publish Platform Packages (Dry Run) | |
if: github.event_name == 'pull_request' | |
run: | | |
for pkg in darwin-arm64 darwin-x64 linux-x64-gnu linux-arm64-gnu win32-x64-msvc; do | |
echo "\n==== Dry run publishing $pkg package ====" | |
cd libs/$pkg | |
npm pack --dry-run | |
cd ../.. | |
done | |
- name: Publish Core Package | |
if: startsWith(github.ref, 'refs/tags/v') | |
run: | | |
cd libs/core | |
npm publish --provenance --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Publish Platform Packages | |
if: startsWith(github.ref, 'refs/tags/v') | |
run: | | |
for pkg in darwin-arm64 darwin-x64 linux-x64-gnu linux-arm64-gnu win32-x64-msvc; do | |
echo "\n==== Publishing $pkg package ====" | |
cd libs/$pkg | |
npm publish --provenance --access public | |
cd ../.. | |
done | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |