name: Verify configuration

env:
    GITEA_TOKEN: ${{ secrets.GIT_TOKEN }}
    SERVER_PORT: 50000
    VOICE_CHAT_PORT: 50001
    RCON_PORT: 50002
    BLUEMAP_PORT: 50003
    GEYSER_PORT: 50004

jobs:
   verify-healthy:
    runs-on: linux-amd64

    steps:
      - uses: actions/checkout@v4

      - name: Start stack
        run: docker compose up -d

      - name: Check health
        run: |
            for i in {1..60}; do
                status=$(docker inspect --format='{{if .State.Health}}{{.State.Health.Status}}{{else}}starting{{end}}' minecraftserver-mc-1 2>/dev/null || echo "missing")
                if [ "$status" = "healthy" ]; then
                    echo "Server healthy"
                    exit 0
                fi
            sleep 5
            done
            
            echo "Server failed health check"
            exit 1

      - name: Cleanup
        if: always()
        run: docker compose down -v