name: Build Graph Node Native Modules on: push: branches: [main] paths: - 'crates/ruvector-graph/**' - 'crates/ruvector-graph-node/**' - 'npm/packages/graph-node/**' - '.github/workflows/build-graph-node.yml' tags: - 'v*' pull_request: branches: [main] paths: - '.github/workflows/build-graph-node.yml' - 'crates/ruvector-graph/**' - 'crates/ruvector-graph-node/**' - 'npm/packages/graph-node/**' workflow_dispatch: inputs: publish: description: 'Publish to npm after build' required: false type: boolean default: false env: CARGO_TERM_COLOR: always jobs: build: strategy: fail-fast: false matrix: settings: - host: ubuntu-24.04 container: ubuntu:22.04 target: x86_64-unknown-linux-gnu platform: linux-x64-gnu - host: ubuntu-24.04 container: ubuntu:22.04 target: aarch64-unknown-linux-gnu platform: linux-arm64-gnu - host: macos-15 target: x86_64-apple-darwin platform: darwin-x64 - host: macos-15 target: aarch64-apple-darwin platform: darwin-arm64 - host: windows-2022 target: x86_64-pc-windows-msvc platform: win32-x64-msvc name: Build Graph ${{ matrix.settings.platform }} runs-on: ${{ matrix.settings.host }} container: ${{ matrix.settings.container }} steps: - name: Bootstrap ubuntu:22.04 build container (keeps the glibc floor) if: ${{ matrix.settings.container != '' }} shell: bash run: | apt-get update DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ sudo git curl wget ca-certificates build-essential pkg-config xz-utils unzip zip python3 jq file \ libssl-dev cmake clang libclang-dev git config --global --add safe.directory '*' - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - name: Setup Node.js uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 with: node-version: '18' - name: Setup Rust uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 with: toolchain: stable targets: ${{ matrix.settings.target }} - name: Cache Rust uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 with: key: graph-node-${{ matrix.settings.target }} - name: Install cross-compilation tools (Linux ARM64) if: matrix.settings.platform == 'linux-arm64-gnu' run: | sudo apt-get update sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - name: Install dependencies working-directory: npm/packages/graph-node run: npm install --ignore-scripts --omit=optional --force - name: Build native module working-directory: npm/packages/graph-node run: | npx napi build --platform --release --cargo-cwd ../../../crates/ruvector-graph-node --target ${{ matrix.settings.target }} env: CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc - name: Find built .node files (debug) shell: bash run: | echo "=== Searching for Graph .node files ===" find npm/packages/graph-node -name "*.node" -type f 2>/dev/null || true - name: Prepare artifact shell: bash run: | mkdir -p graph-artifacts/${{ matrix.settings.platform }} # napi --platform writes exactly index..node in the package # dir. Do NOT `find | head -1`: anything else matching index.*.node # (a host binary pulled into node_modules, a stale local build) could # be picked instead, which is how attention shipped an x86-64 file as # linux-arm64-gnu (#1456). NODE_FILE="npm/packages/graph-node/index.${{ matrix.settings.platform }}.node" if [ ! -f "$NODE_FILE" ]; then echo "ERROR: expected napi output $NODE_FILE not found" find npm/packages/graph-node -name "*.node" -type f exit 1 fi echo "Found: $NODE_FILE" cp -v "$NODE_FILE" "graph-artifacts/${{ matrix.settings.platform }}/" - name: Assert binary architecture matches the platform if: runner.os != 'Windows' shell: bash run: | F="graph-artifacts/${{ matrix.settings.platform }}/index.${{ matrix.settings.platform }}.node" desc=$(file -b "$F"); echo "$F: $desc" case "${{ matrix.settings.platform }}" in linux-x64-gnu) want='ELF 64-bit.*x86-64' ;; linux-arm64-gnu) want='ELF 64-bit.*(ARM aarch64|aarch64)' ;; darwin-x64) want='Mach-O 64-bit.*x86_64' ;; darwin-arm64) want='Mach-O 64-bit.*arm64' ;; esac echo "$desc" | grep -Eq "$want" || { echo "::error::$F is not a ${{ matrix.settings.platform }} binary: $desc"; exit 1; } - name: Gate linux-arm64 binary (no LDAPR, GLIBC <= 2.34) if: matrix.settings.platform == 'linux-arm64-gnu' shell: bash run: bash scripts/ci/check-arm64-node-binary.sh graph-artifacts/linux-arm64-gnu/index.linux-arm64-gnu.node - name: Run the test suite on a Cortex-A72 (Pi 4) under qemu if: matrix.settings.platform == 'linux-arm64-gnu' shell: bash run: | # ARMv8.0 CPU model: any LDAPR (ARMv8.3) or other post-v8.0 instruction # dies with SIGILL here, as it does on a Pi 4 / Jetson. sudo apt-get install -y --no-install-recommends qemu-user curl -fsSL https://nodejs.org/dist/v20.18.1/node-v20.18.1-linux-arm64.tar.xz | tar xJ -C "$RUNNER_TEMP" cd npm/packages/graph-node # index.js loads ./index.linux-arm64-gnu.node (the fresh build) first. qemu-aarch64 -cpu cortex-a72 -L /usr/aarch64-linux-gnu "$RUNNER_TEMP/node-v20.18.1-linux-arm64/bin/node" test.js - name: Test native module (native platform only) if: | (matrix.settings.platform == 'linux-x64-gnu' && runner.os == 'Linux') || (matrix.settings.platform == 'darwin-x64' && runner.os == 'macOS' && runner.arch == 'X64') || (matrix.settings.platform == 'darwin-arm64' && runner.os == 'macOS' && runner.arch == 'ARM64') || (matrix.settings.platform == 'win32-x64-msvc' && runner.os == 'Windows') continue-on-error: true working-directory: npm/packages/graph-node run: npm test - name: Upload artifact uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 with: name: graph-node-${{ matrix.settings.platform }} path: graph-artifacts/${{ matrix.settings.platform }}/*.node if-no-files-found: error publish: name: Publish Graph Node Platform Packages runs-on: ubuntu-24.04 needs: build if: inputs.publish == true || startsWith(github.ref, 'refs/tags/v') steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - name: Setup Node.js uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 with: node-version: '18' registry-url: 'https://registry.npmjs.org' - name: Download all artifacts uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 with: path: artifacts - name: Copy binaries to package run: | for dir in artifacts/graph-node-*/; do platform=$(basename "$dir" | sed 's/graph-node-//') NODE_FILE=$(find "$dir" -name "*.node" | head -1) if [ -n "$NODE_FILE" ]; then cp -v "$NODE_FILE" "npm/packages/graph-node/index.${platform}.node" fi done ls -la npm/packages/graph-node/*.node - name: Publish platform packages working-directory: npm/packages/graph-node env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: node scripts/publish-platforms.js - name: Lock platform optionalDependencies to package version working-directory: npm/packages/graph-node run: | # The platform packages above were just published at this version; # without this the wrapper kept pointing at the previous release. node -e ' const fs = require("fs"); const p = require("./package.json"); const v = p.version; const prefix = p.name + "-"; for (const k of Object.keys(p.optionalDependencies || {})) { if (k.startsWith(prefix)) p.optionalDependencies[k] = v; } fs.writeFileSync("./package.json", JSON.stringify(p, null, 2) + "\n"); console.log("Locked platform optionalDependencies to " + v); ' - name: Publish main package working-directory: npm/packages/graph-node env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: | # Same class as #1007: never swallow a failed publish. VERSION=$(node -p "require('./package.json').version") if npm view "@ruvector/graph-node@${VERSION}" version >/dev/null 2>&1; then echo "@ruvector/graph-node@${VERSION} already published" else npm publish --access public fi - name: Verify all packages are on the registry working-directory: npm/packages/graph-node run: | VERSION=$(node -p "require('./package.json').version") for pkg in @ruvector/graph-node @ruvector/graph-node-linux-x64-gnu \ @ruvector/graph-node-linux-arm64-gnu @ruvector/graph-node-darwin-x64 \ @ruvector/graph-node-darwin-arm64 @ruvector/graph-node-win32-x64-msvc; do ok=0 for i in $(seq 1 72); do if npm view "${pkg}@${VERSION}" version >/dev/null 2>&1; then ok=1; break; fi echo "waiting for ${pkg}@${VERSION} to propagate (attempt ${i}/72)..." sleep 10 done if [ "$ok" != 1 ]; then echo "::error::${pkg}@${VERSION} is not resolvable on npm" exit 1 fi echo "verified ${pkg}@${VERSION}" done