name: Test

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.24'
          cache: true

      - name: Set up pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 9

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '24'
          cache: 'pnpm'
          cache-dependency-path: ui/pnpm-lock.yaml

      - name: Build UI
        run: |
          cd ui
          pnpm install --frozen-lockfile
          pnpm run build

      - name: Build templates
        run: |
          for dir in templates/*/; do
            name=$(basename "$dir")
            echo "Creating $name.tar.gz..."
            tar -czf "templates/$name.tar.gz" -C "templates/$name" --exclude='.DS_Store' .
          done

      - name: Run Go tests
        run: go test -v ./...
