From 1efefb61309edb1d035a322d75304aa981ce939d Mon Sep 17 00:00:00 2001 From: Predrag Gruevski Date: Thu, 5 Dec 2024 18:25:45 +0000 Subject: [PATCH] Add workflow for building and testing Rust Node.js bindings. --- .github/workflows/test_langsmith_nodejs.yml | 241 +++++++++++++++++++- rust/crates/langsmith-nodejs/Cargo.toml | 2 +- 2 files changed, 240 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_langsmith_nodejs.yml b/.github/workflows/test_langsmith_nodejs.yml index 281919415..048b0f338 100644 --- a/.github/workflows/test_langsmith_nodejs.yml +++ b/.github/workflows/test_langsmith_nodejs.yml @@ -26,10 +26,247 @@ permissions: env: RUST_VERSION: '1.82' + NODEJS_VERSION: 22 RUST_WORKSPACE_PATH: 'rust' # The location of the Rust workspace relative to the repo root. + BINDINGS_RELATIVE_PATH: 'crates/langsmith-nodejs' # Bindings path relative to the Rust workspace. + MACOSX_DEPLOYMENT_TARGET: '13' # This governs what SDK we use & the oldest supported macOS. jobs: build: - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + settings: + - host: macos-15 + target: aarch64-apple-darwin + build: | + cd "$BINDINGS_RELATIVE_PATH" + yarn build + strip -x *.node + - host: windows-latest + target: x86_64-pc-windows-msvc + build: | + cd "$BINDINGS_RELATIVE_PATH" + yarn build + - host: ubuntu-latest + target: x86_64-unknown-linux-gnu + docker: | + docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" "$DOCKER_REGISTRY_URL" + docker pull "$DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian" + docker tag "$DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian" builder + build: | + docker run \ + --rm \ + -v ~/.cargo/git:/root/.cargo/git \ + -v ~/.cargo/registry:/root/.cargo/registry \ + -v "$(pwd):/build" \ + -w /build \ + builder \ + /bin/bash -c \ + "cd "$BINDINGS_RELATIVE_PATH" && \ + yarn build && \ + strip langsmith-nodejs.linux-x64-gnu.node" + - host: ubuntu-latest + target: x86_64-unknown-linux-musl + docker: | + docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" "$DOCKER_REGISTRY_URL" + docker pull "$DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine" + docker tag "$DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine" builder + build: | + docker run \ + --rm \ + -v ~/.cargo/git:/root/.cargo/git \ + -v ~/.cargo/registry:/root/.cargo/registry \ + -v "$(pwd):/build" \ + -w /build \ + builder \ + /bin/bash -c \ + "cd "$BINDINGS_RELATIVE_PATH" && \ + yarn build && \ + strip langsmith-nodejs.linux-x64-musl.node" + name: build ${{ matrix.settings.target }} + runs-on: ${{ matrix.settings.host }} steps: - - run: echo 'hello world' + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODEJS_VERSION }} + check-latest: true + + - name: Install rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: "${{ env.RUST_VERSION }}" + cache-workspaces: "${{ env.RUST_WORKSPACE_PATH }} -> target" + rustflags: "" + target: "${{ matrix.settings.target }}" + + - name: Cache NPM dependencies + uses: actions/cache@v4 + with: + path: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}/node_modules" + key: langsmith-nodejs-build-npm-cache-${{ matrix.settings.target }}-node@${{ env.NODEJS_VERSION }}-${{ hashFiles('yarn.lock') }} + + - name: Pull latest image + env: + DOCKER_REGISTRY_URL: ghcr.io + DOCKER_USERNAME: ${{ github.actor }} + DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} + run: ${{ matrix.settings.docker }} + + - name: Install dependencies + working-directory: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}" + shell: bash + run: | + yarn install \ + --ignore-scripts \ + --frozen-lockfile \ + --registry https://registry.npmjs.org \ + --network-timeout 300000 + + - name: Build + working-directory: "${{ env.RUST_WORKSPACE_PATH }}" + shell: bash + run: | + set -euxo pipefail + ${{ matrix.settings.build }} + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: "bindings-${{ matrix.settings.target }}" + path: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}/langsmith-nodejs.*.node" + + test-macos-windows-bindings: + name: "Test bindings ${{ matrix.settings.target }} - node@${{ matrix.node }}" + needs: + - build + strategy: + fail-fast: false + matrix: + settings: + - host: windows-latest + target: x86_64-pc-windows-msvc + - host: macos-15 + target: aarch64 + node: + - '18' + - '20' + - '22' + runs-on: ${{ matrix.settings.host }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODEJS_VERSION }} + check-latest: true + + - name: Cache NPM dependencies + uses: actions/cache@v4 + with: + path: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}/node_modules" + key: langsmith-nodejs-test-npm-cache-${{ matrix.settings.target }}-${{ matrix.node }}-${{ hashFiles('yarn.lock') }} + + - name: Install dependencies + working-directory: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}" + shell: bash + run: | + yarn install \ + --ignore-scripts \ + --frozen-lockfile \ + --registry https://registry.npmjs.org \ + --network-timeout 300000 + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: bindings-${{ matrix.settings.bindings-target }} + path: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}" + + - name: Test bindings + working-directory: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}" + shell: bash + run: | + # List downloaded bindings + ls -R . + + # Run tests. + yarn test + + test-linux-bindings: + name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }} + needs: + - build + strategy: + fail-fast: false + matrix: + settings: + - host: ubuntu-latest + target: x86_64-unknown-linux-gnu + docker-suffix: slim + - host: ubuntu-latest + target: x86_64-unknown-linux-musl + docker-suffix: alpine + node: + - '18' + - '20' + - '22' + runs-on: "${{ matrix.settings.host }}" + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODEJS_VERSION }} + check-latest: true + + - name: Cache NPM dependencies + uses: actions/cache@v4 + with: + path: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}/node_modules" + key: langsmith-nodejs-test-npm-cache-${{ matrix.settings.target }}-${{ matrix.node }}-${{ hashFiles('yarn.lock') }} + + - name: Install dependencies + working-directory: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}" + shell: bash + run: | + yarn install \ + --ignore-scripts \ + --frozen-lockfile \ + --registry https://registry.npmjs.org \ + --network-timeout 300000 + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: bindings-${{ matrix.settings.target }} + path: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}" + + - name: Test bindings + working-directory: "${{ env.RUST_WORKSPACE_PATH }}" + shell: bash + run: | + # List downloaded bindings + ls -R "$BINDINGS_RELATIVE_PATH" + + # Run tests. + docker run \ + --rm \ + -v "$(pwd):/rust" \ + -w "/rust/$BINDINGS_RELATIVE_PATH" \ + node:${{ matrix.node }}-${{ matrix.settings.docker-suffix }} \ + yarn test diff --git a/rust/crates/langsmith-nodejs/Cargo.toml b/rust/crates/langsmith-nodejs/Cargo.toml index 475442ff5..8fad5fc8f 100644 --- a/rust/crates/langsmith-nodejs/Cargo.toml +++ b/rust/crates/langsmith-nodejs/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "langsmith-nodejs" version = "0.1.0" -edition = "2024" +edition = "2021" [lib] # "cdylib" is necessary to produce a shared library for Node.js to import from.