#!/usr/bin/env bash
set -euo pipefail

export PATH="/usr/local/go/bin:$PATH"

BIN="bin"
TAGS="-tags goolm"
LDFLAGS="-ldflags=-s -w"

mkdir -p "$BIN"

echo "==> Ejecutando tests..."
go test $TAGS ./...
echo ""

echo "==> Compilando todos los binarios en $BIN/ ..."

targets=(
    "launcher:./cmd/launcher"
    "agentctl:./cmd/agentctl"
    "register:./cmd/register"
    "dashboard:./cmd/dashboard"
)

for entry in "${targets[@]}"; do
    name="${entry%%:*}"
    pkg="${entry##*:}"
    echo "    $name"
    go build $TAGS "$LDFLAGS" -o "$BIN/$name" "$pkg"
done

echo ""
echo "==> Listo. Binarios disponibles:"
ls -lh "$BIN"/
