SUBDIRS = src # =========================== # Configurações de Git # =========================== GIT_USER ?= "neo.webmaster.2@gmail.com" GIT_EMAIL ?= "neo.webmaster.2@gmail.com" GIT_REMOTE ?= "origin" GIT_BRANCH ?= "main" COMMIT_MSG ?= "Auto-commit via make git" # =========================== # Caminhos e artefactos # =========================== DIST_DIR ?= $(top_builddir)/dist BUILD_DIR ?= $(top_builddir)/build SRC_TAR ?= $(DIST_DIR)/neoricalex-src.tar.gz # =========================== # Alvos principais # =========================== .PHONY: all tarball git release run clean-local check-remote all: $(DIST_DIR) $(DIST_DIR): mkdir -p $(DIST_DIR) # =========================== # Empacotamento do código-fonte # =========================== tarball: $(SRC_TAR) $(SRC_TAR): @echo "[TAR] Empacotando código-fonte..." mkdir -p $(DIST_DIR) cd $(top_srcdir) && tar \ --exclude="$(notdir $(SRC_TAR))" \ --exclude="$(DIST_DIR)" \ --exclude="$(BUILD_DIR)" \ --exclude='*/__pycache__' \ --exclude='*/.venv' \ --exclude='*/venv' \ --exclude='*.pyc' \ --exclude='*.pyo' \ --exclude='*.o' \ --exclude='*.a' \ --exclude='*.so' \ -czf $(SRC_TAR) . @echo "[✔] Tarball gerado em $(SRC_TAR)" # =========================== # Git (commit + push) # =========================== git: check-remote @echo "📦 Commit automático → Gitea" @git config user.name $(GIT_USER) @git config user.email $(GIT_EMAIL) @git rev-parse --abbrev-ref HEAD >/dev/null 2>&1 || true @git add -A @git commit -m "$$(echo "$(COMMIT_MSG)")" || echo "Nenhuma modificação para commitar." @git push $(GIT_REMOTE) $(GIT_BRANCH) # =========================== # Release (Tarball) # =========================== release: tarball check-remote @echo "🚀 Publicando build em dist/releases" @mkdir -p $(DIST_DIR)/releases @if ls $(DIST_DIR)/neoricalex-*.tar.gz >/dev/null 2>&1; then \ cp $(DIST_DIR)/neoricalex-*.tar.gz $(DIST_DIR)/releases/; \ else \ echo "⚠️ Nenhum tarball encontrado. Execute 'make tarball' primeiro."; \ fi @git add $(DIST_DIR)/releases/ @git commit -m "Build automático: release $(shell date +%F_%H-%M)" || echo "Nenhum ficheiro novo para commitar." @git push origin main @TAG="v$(shell date +%Y.%m.%d-%H%M)" && \ echo "🏷 Criando tag $$TAG" && \ git tag -a $$TAG -m "Release automática em $$TAG" && \ git push origin $$TAG || echo "⚠️ Tag já existente ou erro ao criar." # =========================== # Git Remote (HTTPS → SSH Auto-Fix) # =========================== check-remote: @REMOTE_URL=$$(git remote get-url $(GIT_REMOTE)); \ if echo $$REMOTE_URL | grep -q '^https://gitea\.neoricalex\.com'; then \ echo "⚠️ Repositório configurado com HTTPS:"; \ echo " $$REMOTE_URL"; \ echo "🔄 Convertendo para SSH (porta 2222)..."; \ SSH_URL=$$(echo $$REMOTE_URL | sed -E 's|https://gitea\.neoricalex\.com[:/]+|ssh://git@gitea.neoricalex.com:2222/|'); \ git remote set-url $(GIT_REMOTE) $$SSH_URL; \ echo "✅ Remote atualizado para:"; \ git remote -v; \ else \ echo "✅ Remote SSH já configurado:"; \ git remote -v | grep $(GIT_REMOTE); \ fi; \ echo "🔍 Testando conectividade SSH com Gitea..."; \ if ssh -T git@gitea.neoricalex.com -p 2222 2>&1 | grep -q "successfully authenticated"; then \ echo "✅ Conexão SSH funcional com Gitea."; \ else \ echo "❌ Falha na autenticação SSH com Gitea."; \ echo " Verifique a chave em ~/.ssh/id_ed25519.pub e nas SSH Keys do Gitea."; \ exit 1; \ fi # =========================== # Teste # =========================== run: @python3 src/manager/manager_main.py # =========================== # Limpeza # =========================== clean-local: @echo "[CLEAN] Removendo diretórios temporários..." rm -rf $(BUILD_DIR) find $(DIST_DIR) -type f ! -path "$(DIST_DIR)/releases/*" -delete @echo "[✔] Limpeza concluída (releases preservadas)"