name: CI
on:
  pull_request:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6
      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
      - name: Install Node.js
        uses: actions/setup-node@v6
        with:
          node-version: lts/*
      - name: Cache Cargo dependencies
        uses: actions/cache@v6
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
      - name: Cache npm dependencies
        uses: actions/cache@v6
        with:
          path: app/node_modules
          key: ${{ runner.os }}-npm-${{ hashFiles('app/package-lock.json') }}
      - name: Install frontend dependencies
        run: npm ci
        working-directory: app
      - name: Run Rust tests
        run: cargo test --workspace
      - name: Run Clippy
        run: cargo clippy --workspace -- -D warnings
      - name: Run Rust fmt check
        run: cargo fmt --all -- --check
      - name: Run frontend tests
        run: npm test
        working-directory: app
      - name: Run ESLint
        run: npm run lint
        working-directory: app
      - name: Run Prettier check
        run: npm run format:check
        working-directory: app
