Skip to content

ci: Fix builds (#2) #55

ci: Fix builds (#2)

ci: Fix builds (#2) #55

Workflow file for this run

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 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 artifacts
uses: actions/download-artifact@v4
with:
name: bindings-${{ matrix.target }}
- 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
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: Move artifacts
run: |
echo "Debug: Showing all downloaded artifacts:"
find . -type f -name "*.node" -ls
echo "\nMoving only cel-typescript binaries to root:"
find . -type f -name "cel-typescript.*.node" -exec mv {} . \;
echo "\nBinaries in root directory:"
ls -la cel-typescript.*.node
# Count our binaries
node_count=$(ls -1 cel-typescript.*.node 2>/dev/null | wc -l)
expected_count=5 # We target 5 platforms
echo "\nFound $node_count cel-typescript binaries (expected $expected_count)"
if [ "$node_count" -ne "$expected_count" ]; then
echo "Error: Expected $expected_count binaries but found $node_count"
exit 1
fi
- name: Build TypeScript
run: npm run build:ts
- name: Verify package contents
run: |
echo "Package contents:"
npm pack --dry-run
- name: Publish
if: startsWith(github.ref, 'refs/tags/v')
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish (Dry Run)
if: github.event_name == 'pull_request'
run: npm publish --dry-run