chore: Fix builds #78
Workflow file for this run
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 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 | |
| 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 "\nMoving binaries to their respective package directories:" | |
| # Copy binaries to their package directories | |
| find . -name "cel-typescript.darwin-arm64.node" -exec cp {} libs/darwin-arm64/ \; | |
| find . -name "cel-typescript.darwin-x64.node" -exec cp {} libs/darwin-x64/ \; | |
| find . -name "cel-typescript.linux-x64-gnu.node" -exec cp {} libs/linux-x64-gnu/ \; | |
| find . -name "cel-typescript.linux-arm64-gnu.node" -exec cp {} libs/linux-arm64-gnu/ \; | |
| find . -name "cel-typescript.win32-x64-msvc.node" -exec cp {} libs/win32-x64-msvc/ \; | |
| # Count our binaries to ensure we have all of them | |
| node_count=$(find libs -name "cel-typescript.*.node" | wc -l) | |
| expected_count=5 # We target 5 platforms | |
| echo "\nFound $node_count cel-typescript binaries in package directories (expected $expected_count)" | |
| if [ "$node_count" -ne "$expected_count" ]; then | |
| echo "Error: Expected $expected_count binaries but found $node_count" | |
| 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 }} |