name: CI

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

jobs:
  # ── Go Backend ──────────────────────────────────────────
  tongo-core:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v4

      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.23'

      - name: Lint
        working-directory: tongo-core
        run: |
          go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
          golangci-lint run ./...

      - name: Test
        working-directory: tongo-core
        run: go test -race -coverprofile=coverage.out ./...

      - name: Build
        working-directory: tongo-core
        run: go build -o bin/tongo-core ./cmd/tongo-core

  # ── Frontend ────────────────────────────────────────────
  web-terminal:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: '22'

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

      - name: Lint & Format Check
        working-directory: web-terminal
        run: npm run format

      - name: Type Check
        working-directory: web-terminal
        run: npx tsc --noEmit

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