126 lines
4.1 KiB
Makefile
126 lines
4.1 KiB
Makefile
SUBDIRS = src
|
|
|
|
# ===========================
|
|
# Caminhos e artefactos
|
|
# ===========================
|
|
TOP_DIR = $(shell pwd)
|
|
DIST_DIR = $(TOP_DIR)/dist
|
|
BUILD_DIR = $(TOP_DIR)/build
|
|
GIT_VER = $(shell git describe --tags --always --dirty 2>/dev/null || echo "0.1-dev")
|
|
SRC_TAR = $(DIST_DIR)/neoricalex-$(GIT_VER)-src.tar.gz
|
|
|
|
# ===========================
|
|
# 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"
|
|
|
|
# ===========================
|
|
# 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 (versão $(GIT_VER))..."
|
|
@mkdir -p "$(DIST_DIR)" "$(BUILD_DIR)"
|
|
cd "$(TOP_DIR)" && 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 + Tag)
|
|
# ===========================
|
|
release: tarball check-remote
|
|
@echo "🚀 Publicando build em dist/releases (versão: $(GIT_VER))"
|
|
@mkdir -p $(DIST_DIR)/releases
|
|
@cp $(SRC_TAR) $(DIST_DIR)/releases/ 2>/dev/null || echo "⚠️ Nenhum tarball encontrado. Execute 'make tarball' primeiro."
|
|
@echo "📦 Adicionando releases ignoradas (forçado)"
|
|
@git add -f $(DIST_DIR)/releases/* 2>/dev/null || echo "⚠️ Nenhum artefato novo para adicionar."
|
|
@git commit -m "Build automático: release $(GIT_VER)" || echo "Nenhum ficheiro novo para commitar."
|
|
@git push origin main
|
|
@TAG="$(GIT_VER)"; \
|
|
if git rev-parse "$$TAG" >/dev/null 2>&1; then \
|
|
echo "⚠️ Tag $$TAG já existente."; \
|
|
else \
|
|
echo "🏷 Criando tag $$TAG"; \
|
|
git tag -a "$$TAG" -m "Release automática $$TAG"; \
|
|
git push origin "$$TAG"; \
|
|
fi
|
|
|
|
# ===========================
|
|
# 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) -maxdepth 1 -type f ! -path "$(DIST_DIR)/releases/*" -delete 2>/dev/null || true
|
|
@echo "[✔] Limpeza concluída (releases preservadas)"
|