nb-cli 0.0.9

A command-line tool for reading, writing, and executing Jupyter notebooks
name: Rust

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

env:
  CARGO_TERM_COLOR: always
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

jobs:
  lint:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - name: cargo fmt
      run: cargo fmt -- --check

    - name: cargo clippy
      run: cargo clippy -- -D warnings

  test:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - name: Set up Rust cache
      uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/bin/
          ~/.cargo/registry/index/
          ~/.cargo/registry/cache/
          ~/.cargo/git/db/
          target/
        key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
        restore-keys: |
          ${{ runner.os }}-cargo-

    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.11'

    - name: Install uv
      uses: astral-sh/setup-uv@v5
      with:
        enable-cache: true

    - name: Cache Python test venv
      uses: actions/cache@v4
      with:
        path: tests/.test-venv
        key: ${{ runner.os }}-test-venv-${{ hashFiles('requirements.txt') }}
        restore-keys: |
          ${{ runner.os }}-test-venv-

    - name: Setup test environment
      run: ./tests/setup_test_env.sh

    - name: Build
      run: cargo build --verbose

    - name: Run tests
      run: |
        echo "Running all tests..."
        cargo test --test integration_local_mode --verbose
        cargo test --test integration_execution --verbose
        cargo test --bins --verbose
        echo "✅ All tests passed!"

    # Connect-mode tests require a running Jupyter server and are not run in CI by default.
    # To enable, set RUN_CONNECT_TESTS=true in the workflow environment and ensure
    # jupyter_server + jupyter-server-documents are installed in the test venv.
    # Note: must use --test-threads=1 to avoid races on the shared Jupyter server.
    #
    # - name: Run connect-mode tests
    #   if: env.RUN_CONNECT_TESTS == 'true'
    #   run: cargo test --test integration_connect_mode -- --test-threads=1

  test-windows:
    name: Test (Windows)
    runs-on: windows-latest
    permissions:
      contents: write

    steps:
    - uses: actions/checkout@v4

    - name: Set up Rust cache
      uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/bin/
          ~/.cargo/registry/index/
          ~/.cargo/registry/cache/
          ~/.cargo/git/db/
          target/
        key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
        restore-keys: |
          ${{ runner.os }}-cargo-

    - name: Install Rust target
      run: rustup target add x86_64-pc-windows-msvc

    - name: Build release binary
      run: cargo build --release --target x86_64-pc-windows-msvc

    - name: Run unit tests (kernel discovery)
      # Integration tests require a Unix shell setup script; run unit tests only.
      # This verifies Windows-specific #[cfg(target_os = "windows")] code paths compile
      # and that kernel directory logic is correct on Windows.
      run: cargo test --bins --verbose

    - name: Upload Windows binary
      uses: actions/upload-artifact@v4
      with:
        name: nb-windows-amd64
        path: target/x86_64-pc-windows-msvc/release/nb.exe
        retention-days: 30