name: CI

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

jobs:
  backend:
    name: Go Build & Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.25'
          cache-dependency-path: server/go.sum

      - name: Build
        working-directory: server
        run: go build ./...

      - name: Test
        working-directory: server
        run: go test ./... -v

  frontend:
    name: React Build & Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
          cache-dependency-path: web/package-lock.json

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

      - name: Type Check
        working-directory: web
        run: npx tsc --noEmit -p tsconfig.json

      - name: Test
        working-directory: web
        run: npm run test

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