Skip to content

Commit

Permalink
Add workflow for building and testing Rust Node.js bindings.
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Dec 5, 2024
1 parent 2b9f1f7 commit 12f8b84
Show file tree
Hide file tree
Showing 2 changed files with 239 additions and 3 deletions.
240 changes: 238 additions & 2 deletions .github/workflows/test_langsmith_nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,246 @@ 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 "$RUST_WORKSPACE_PATH/$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 "$RUST_WORKSPACE_PATH/$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
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
2 changes: 1 addition & 1 deletion rust/crates/langsmith-nodejs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 12f8b84

Please sign in to comment.