name: CI

on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

jobs:
  lint-typecheck:
    name: Lint & TypeScript
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
          cache-dependency-path: desktop/ui/package-lock.json

      - name: Install UI deps
        run: cd desktop/ui && npm ci

      - name: Lint
        run: cd desktop/ui && npm run lint

      - name: TypeScript
        run: cd desktop/ui && npx tsc --noEmit

  rust-check:
    name: Rust check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
      - name: Cache Cargo
        uses: actions/cache@v4
        with:
          path: |
            desktop/src-tauri/target
            ~/.cargo/registry
            ~/.cargo/git
          key: ${{ runner.os }}-cargo-${{ hashFiles('desktop/src-tauri/Cargo.lock') }}

      - name: Check
        run: cd desktop/src-tauri && cargo check
