.PHONY: help up down logs status clean push

.DEFAULT_GOAL := help

COMPOSE     := docker compose
GITEA_USER  := galaxy
GITEA_PASS  := galaxy-dev
REPO_NAME   := galaxy
REMOTE_NAME := local-gitea
REPO_ROOT   := $(realpath $(CURDIR)/../..)
GIT         := git -C $(REPO_ROOT)
REMOTE_URL  := http://$(GITEA_USER):$(GITEA_PASS)@localhost:3000/$(GITEA_USER)/$(REPO_NAME).git

help:
	@echo "Local Gitea CI for galaxy:"
	@echo "  make up         Bring up Gitea + runner (idempotent)"
	@echo "  make down       Stop both containers"
	@echo "  make logs       Tail logs"
	@echo "  make status     Show container status"
	@echo "  make push       Push current branch to local Gitea"
	@echo "  make clean      Stop and wipe all local state"

up:
	@./bootstrap.sh

down:
	$(COMPOSE) down

logs:
	$(COMPOSE) logs -f --tail=50

status:
	$(COMPOSE) ps

push:
	@$(GIT) remote get-url $(REMOTE_NAME) >/dev/null 2>&1 || \
	    $(GIT) remote add $(REMOTE_NAME) $(REMOTE_URL)
	$(GIT) push $(REMOTE_NAME) HEAD

clean:
	$(COMPOSE) down -v
	rm -f .env
