name: CI

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

jobs:
  backend:
    name: Backend (Rust)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

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

      - name: Check
        working-directory: backend
        run: cargo check

      - name: Test
        working-directory: backend
        run: cargo test

      - name: Format check
        working-directory: backend
        run: cargo fmt -- --check

  frontend:
    name: Frontend (Vue)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
          cache-dependency-path: frontend/package-lock.json

      - name: Install dependencies
        working-directory: frontend
        run: npm ci

      - name: Type check
        working-directory: frontend
        run: npx vue-tsc --noEmit
        continue-on-error: true

      - name: Build
        working-directory: frontend
        run: npm run build
