-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run tests and lint for Rust code in CI. (#1289)
Run tools like `clippy`, `cargo fmt`, `cargo doc`, and tests over our Rust code in CI.
- Loading branch information
1 parent
6106403
commit 47be091
Showing
3 changed files
with
139 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
name: Run Rust CI | ||
|
||
# Our Rust code depends on the vendored `orjson` and `pyo3` workspaces, | ||
# so ensure that CI re-runs if they are modified. | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- "rust/**" | ||
- "vendor/orjson/**" | ||
- "vendor/pyo3/**" | ||
- ".github/workflows/rust_test.yml" | ||
pull_request: | ||
paths: | ||
- "rust/**" | ||
- "vendor/orjson/**" | ||
- "vendor/pyo3/**" | ||
- ".github/workflows/rust_test.yml" | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
|
||
env: | ||
RUST_VERSION: '1.82' # Be careful, "stable" gets you "whatever GitHub ships", which is quite old. | ||
RUST_WORKSPACE_PATH: 'rust' # The location of the Rust workspace relative to the repo root. | ||
|
||
jobs: | ||
lint: | ||
name: Check lint and rustfmt | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Install rust | ||
uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
with: | ||
toolchain: "${{env.RUST_VERSION}}" | ||
components: rustfmt, clippy | ||
cache-workspaces: "${{env.RUST_WORKSPACE_PATH}} -> target" | ||
rustflags: "" | ||
|
||
- name: cargo clippy | ||
working-directory: ${{env.RUST_WORKSPACE_PATH}} | ||
run: cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings --allow deprecated | ||
|
||
- name: cargo fmt | ||
working-directory: ${{env.RUST_WORKSPACE_PATH}} | ||
run: cargo fmt -- --check | ||
|
||
- name: cargo doc | ||
working-directory: ${{env.RUST_WORKSPACE_PATH}} | ||
env: | ||
RUSTDOCFLAGS: -D warnings | ||
run: cargo doc --workspace --no-deps --document-private-items | ||
cargo-test: | ||
name: Run `cargo test` | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Install rust | ||
uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
with: | ||
toolchain: "${{env.RUST_VERSION}}" | ||
cache-workspaces: "${{env.RUST_WORKSPACE_PATH}} -> target" | ||
rustflags: "" | ||
|
||
- name: cargo test | ||
working-directory: ${{env.RUST_WORKSPACE_PATH}} | ||
run: | | ||
set -euxo pipefail | ||
# We exclude `langsmith-pyo3` since its tests: | ||
# - Have to be run under `nextest`, since they require one-process-per-test. | ||
# - Require a non-default configuration in order to run. | ||
cargo test --workspace --exclude langsmith-pyo3 --all-features | ||
langsmith-pyo3-tests: | ||
name: Run langsmith-pyo3 tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Install rust | ||
uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
with: | ||
toolchain: "${{env.RUST_VERSION}}" | ||
cache-workspaces: "${{env.RUST_WORKSPACE_PATH}} -> target" | ||
rustflags: "" | ||
|
||
- name: Install cargo-nextest | ||
uses: taiki-e/install-action@v2 | ||
with: | ||
tool: cargo-nextest | ||
|
||
- name: cargo test | ||
working-directory: "${{env.RUST_WORKSPACE_PATH}}/crates/langsmith-pyo3" | ||
run: | | ||
set -euxo pipefail | ||
# See the langsmith-pyo3 README.md file for an explanation | ||
# of why tests have to run under nextest & without default features. | ||
cargo nextest run --no-default-features |
This file contains 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
This file contains 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