Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
ci: add type and lint check for agent cli PRs and update ci build workflow (#8649)
Akarshan Biswas7ccd3c6d32ac
diff --git a/.github/workflows/rust-check.yml b/.github/workflows/rust-check.ymlnew file mode 100644index 000000000..e10764b63--- /dev/null+++ b/.github/workflows/rust-check.yml@@ -0,0 +1,107 @@+name: Rust Check+on:+ workflow_dispatch:+ pull_request:+ branches:+ - dev++concurrency:+ group: rust-check-${{ github.ref }}+ cancel-in-progress: true++env:+ CARGO_TERM_COLOR: always++jobs:+ # The desktop and CLI feature sets are mutually exclusive configs of the same+ # crate, so neither one alone proves the other compiles.+ app:+ name: app (${{ matrix.name }})+ runs-on: ubuntu-latest+ strategy:+ fail-fast: false+ matrix:+ include:+ - name: desktop+ features: test-tauri+ targets: --all-targets+ tauri: true+ # Test targets are only exercised in the desktop config, and a+ # headless runner cannot link them here anyway.+ - name: cli+ features: cli+ targets: --lib --bins+ tauri: false+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6++ - uses: dtolnay/rust-toolchain@stable+ with:+ components: clippy++ - uses: Swatinem/rust-cache@v2+ with:+ workspaces: src-tauri+ key: ${{ matrix.name }}++ - name: Install Tauri dependencies+ if: matrix.tauri+ run: |+ sudo apt update+ sudo apt install -y libglib2.0-dev libatk1.0-dev libpango1.0-dev libgtk-3-dev libsoup-3.0-dev libwebkit2gtk-4.1-dev librsvg2-dev++ - name: Create Tauri resource stubs+ if: matrix.tauri+ run: ./scripts/stub-tauri-resources.sh++ - name: cargo check+ run: |+ cargo check --locked --manifest-path src-tauri/Cargo.toml \+ --no-default-features --features ${{ matrix.features }} ${{ matrix.targets }}++ - name: cargo clippy+ run: |+ cargo clippy --locked --manifest-path src-tauri/Cargo.toml \+ --no-default-features --features ${{ matrix.features }} ${{ matrix.targets }} \+ -- -D warnings++ # Each plugin and src-tauri/utils is its own workspace, so checking the app+ # crate compiles them as path dependencies but never lints them. No --locked+ # here: Cargo.lock is gitignored and only some of these crates commit one.+ crates:+ name: ${{ matrix.crate }}+ runs-on: ubuntu-latest+ strategy:+ fail-fast: false+ matrix:+ # tauri-plugin-mlx is Apple-Silicon-only and is a macOS target+ # dependency, not part of any Linux build.+ crate:+ - plugins/tauri-plugin-agent-tools+ - plugins/tauri-plugin-hardware+ - plugins/tauri-plugin-llamacpp+ - plugins/tauri-plugin-rag+ - plugins/tauri-plugin-vector-db+ - plugins/tauri-plugin-websearch+ - utils+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6++ - uses: dtolnay/rust-toolchain@stable+ with:+ components: clippy++ - uses: Swatinem/rust-cache@v2+ with:+ workspaces: src-tauri/${{ matrix.crate }}++ - name: Install Tauri dependencies+ run: |+ sudo apt update+ sudo apt install -y libglib2.0-dev libatk1.0-dev libpango1.0-dev libgtk-3-dev libsoup-3.0-dev libwebkit2gtk-4.1-dev librsvg2-dev++ - name: cargo check+ run: cargo check --manifest-path src-tauri/${{ matrix.crate }}/Cargo.toml --all-targets++ - name: cargo clippy+ run: cargo clippy --manifest-path src-tauri/${{ matrix.crate }}/Cargo.toml --all-targets -- -D warningsdiff --git a/.github/workflows/template-cli-build-linux-x64.yml b/.github/workflows/template-cli-build-linux-x64.ymlindex 689c4c4c0..c33cf8742 100644--- a/.github/workflows/template-cli-build-linux-x64.yml+++ b/.github/workflows/template-cli-build-linux-x64.yml@@ -48,26 +48,41 @@ jobs:with:toolchain: stable+ # `libdbus-1-dev` used to be required here because keyring's+ # `sync-secret-service` backend links libdbus. That backend is gone (it is+ # now the pure-Rust `async-secret-service`), and installing the dev+ # package would hide a regression: the build would keep succeeding while+ # producing a binary that cannot start on a host without libdbus at all.+ # `pkg-config` stays for openssl-sys.- name: Install system dependenciesrun: |sudo apt-get update- sudo apt-get install -y libdbus-1-dev pkg-config+ sudo apt-get install -y pkg-config- name: Cache cargouses: Swatinem/rust-cache@v2- - name: Assert no GUI crates+ # The CLI must stay free of Tauri/GTK: this runner has no libwebkit2gtk,+ # so a regression here would surface as a confusing linker error later.+ # `dbus`/`libdbus-sys` arrive via keyring's `sync-secret-service` backend;+ # it is pinned to the pure-Rust `async-secret-service` (zbus) instead.+ #+ # `cargo tree -i` exits 0 with "nothing to print" for a crate that is in+ # Cargo.lock but not in *this* feature graph, so the exit code alone does+ # not answer the question -- the previous form of this check could not+ # fail. A non-zero exit means the crate is not in the lockfile at all,+ # which is also a pass.+ - name: Assert no GUI or D-Bus crates in the CLI dependency graphrun: |cd src-tauri- if cargo tree --no-default-features --features cli -i tauri >/dev/null 2>&1 || \- cargo tree --no-default-features --features cli -i gtk >/dev/null 2>&1 || \- cargo tree --no-default-features --features cli -i gdk >/dev/null 2>&1 || \- cargo tree --no-default-features --features cli -i muda >/dev/null 2>&1 || \- cargo tree --no-default-features --features cli -i wry >/dev/null 2>&1 || \- cargo tree --no-default-features --features cli -i webkit2gtk >/dev/null 2>&1; then- echo "GUI crate leaked into the CLI dependency graph" >&2+ for crate in tauri gtk gdk muda wry webkit2gtk dbus libdbus-sys dbus-secret-service; do+ out=$(cargo tree --no-default-features --features cli -e normal \+ --target x86_64-unknown-linux-gnu -i "$crate" 2>&1) || continue+ case "$out" in *"nothing to print"*) continue ;; esac+ echo "::error::$crate is back in the jan CLI dependency graph"+ echo "$out" | head -20exit 1- fi+ done- name: Build CLI binaryenv:@@ -77,6 +92,29 @@ jobs:cd src-tauricargo build --no-default-features --features cli --bin jan --release+ # The crate blocklist above only catches names somebody thought to list.+ # This catches any new dynamic dependency whatever its source: a NEEDED+ # entry is resolved by the loader before `main`, so a host without that+ # library cannot exec `jan` at all and no runtime fallback can rescue it.+ # That is exactly how a missing libdbus-1.so.3 broke headless installs.+ - name: Assert the CLI binary links no unexpected shared libraries+ run: |+ # `comm` requires both inputs collated identically, hence LC_ALL=C.+ export LC_ALL=C+ readelf -d src-tauri/target/release/jan \+ | sed -n 's/.*NEEDED.*\[\(.*\)\].*/\1/p' | sort -u > needed.txt+ echo "linked:"; sed 's/^/ /' needed.txt+ # libssl/libcrypto come from reqwest's default native-tls backend.+ # They are versioned sonames, so the binary still fails on a host with+ # a different OpenSSL; switching reqwest to rustls-tls would drop them.+ printf '%s\n' ld-linux-x86-64.so.2 libc.so.6 libcrypto.so.3 \+ libgcc_s.so.1 libm.so.6 libssl.so.3 | sort -u > allowed.txt+ unexpected=$(comm -23 needed.txt allowed.txt)+ if [ -n "$unexpected" ]; then+ echo "::error::CLI binary gained an unexpected shared library dependency: $(echo $unexpected)"+ exit 1+ fi+- name: Strip binaryrun: strip src-tauri/target/release/jandiff --git a/scripts/rust-coverage.sh b/scripts/rust-coverage.shindex 29e1c930f..9a144ae14 100755--- a/scripts/rust-coverage.sh+++ b/scripts/rust-coverage.sh@@ -3,21 +3,7 @@# Outputs: rust-lcov.info in the current directory.set -euo pipefail-# Tauri build script validates resources, externalBin, and icons exist.-# Create stubs so the build succeeds in CI where these aren't present.-TRIPLE=$(rustc -vV | awk '/^host:/ { print $2 }')-mkdir -p src-tauri/resources/bin src-tauri/resources/pre-install src-tauri/icons-[ -f src-tauri/resources/LICENSE ] || touch src-tauri/resources/LICENSE-[ -f src-tauri/resources/bin/jan-cli ] || touch src-tauri/resources/bin/jan-cli-[ "$(ls -A src-tauri/resources/pre-install 2>/dev/null)" ] || touch src-tauri/resources/pre-install/.gitkeep-for bin in uv bun; do- stub="src-tauri/resources/bin/${bin}-${TRIPLE}"- [ -f "$stub" ] || touch "$stub"-done-# Icons are gitignored; generate_context!() requires them at compile time-for icon in 32x32.png 128x128.png [email protected] icon.icns icon.ico; do- [ -f "src-tauri/icons/$icon" ] || cp src-tauri/icons/icon.png "src-tauri/icons/$icon"-done+"$(dirname "$0")/stub-tauri-resources.sh"cargo llvm-cov clean --workspace --manifest-path src-tauri/Cargo.tomlcargo llvm-cov --no-report --manifest-path src-tauri/Cargo.toml --no-default-features --features test-tauri -- --test-threads=1diff --git a/scripts/stub-tauri-resources.sh b/scripts/stub-tauri-resources.shnew file mode 100755index 000000000..ac7022e6e--- /dev/null+++ b/scripts/stub-tauri-resources.sh@@ -0,0 +1,24 @@+#!/usr/bin/env bash+# The Tauri build script validates resources, externalBin, icons and+# frontendDist exist. Create stubs so a compile-only run succeeds in CI, where+# none of them are built.+set -euo pipefail++TRIPLE=$(rustc -vV | awk '/^host:/ { print $2 }')+mkdir -p src-tauri/resources/bin src-tauri/resources/pre-install src-tauri/icons web-app/dist+[ -f src-tauri/resources/LICENSE ] || touch src-tauri/resources/LICENSE+# The bundled CLI is `jan-cli` on some branches and `jan` on others; the Tauri+# config only asks for one, and stubbing the other costs nothing.+for cli in jan jan-cli; do+ [ -f "src-tauri/resources/bin/$cli" ] || touch "src-tauri/resources/bin/$cli"+done+[ -f web-app/dist/index.html ] || touch web-app/dist/index.html+[ "$(ls -A src-tauri/resources/pre-install 2>/dev/null)" ] || touch src-tauri/resources/pre-install/.gitkeep+for bin in uv bun; do+ stub="src-tauri/resources/bin/${bin}-${TRIPLE}"+ [ -f "$stub" ] || touch "$stub"+done+# Icons are gitignored; generate_context!() requires them at compile time+for icon in 32x32.png 128x128.png [email protected] icon.icns icon.ico; do+ [ -f "src-tauri/icons/$icon" ] || cp src-tauri/icons/icon.png "src-tauri/icons/$icon"+done