name: CI

on:
  push:
    tags-ignore:
      - "v*"
    paths:
      - "backend/**"
      - "ui/**"
      - ".gitea/workflows/ci.yaml"

concurrency:
  group: ${{ gitea.workflow }}-${{ gitea.ref }}
  cancel-in-progress: true

jobs:
  # ── Go: vet + build + test ────────────────────────────────────────────────
  backend:
    name: Backend
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: backend
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-go@v5
        with:
          go-version-file: backend/go.mod
          cache-dependency-path: backend/go.sum

      - name: go vet
        run: go vet ./...

      - name: Build backend
        run: go build -o /dev/null ./cmd/backend

      - name: Build runner
        run: go build -o /dev/null ./cmd/runner

      - name: Build healthcheck
        run: go build -o /dev/null ./cmd/healthcheck

      - name: Run tests
        run: go test -short -race -count=1 -timeout=60s ./...

  # ── UI: type-check + build ────────────────────────────────────────────────
  ui:
    name: UI
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ui
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: "22"
          cache: npm
          cache-dependency-path: ui/package-lock.json

      - name: Install dependencies
        run: npm ci

      - name: Type check
        run: npm run check

      - name: Build
        run: npm run build
