#!/bin/bash
# ============================================
# Gitea Runner Registration Script
# ============================================
# Usage:
#   1. Get token from Gitea Admin > Runners
#   2. Run: RUNNER_TOKEN="your-token" ./register.sh

set -e

GITEA_URL="${INSTANCE_URL:-https://gitea.hackerfortress.cc}"
TOKEN="${RUNNER_TOKEN}"

if [ -z "$TOKEN" ]; then
    echo "❌ RUNNER_TOKEN not set"
    echo "   Get token from: ${GITEA_URL}/admin/runners"
    exit 1
fi

echo "📡 Registering runner with Gitea at ${GITEA_URL}..."

# Register and get the runner config
docker compose run --rm act_runner \
    act_runner generate-config \
    --instance "${GITEA_URL}" \
    --token "${TOKEN}" \
    --name "gitea-runner-dockerino" \
    > config.yaml

echo "✅ Runner registered successfully!"
echo ""
echo "Next steps:"
echo "1. Review config.yaml"
echo "2. Run: docker compose up -d"
