From 5b403d7ee4f31890a73d903cdb846d6bbfc6ffa2 Mon Sep 17 00:00:00 2001 From: Maxim Date: Mon, 13 Jul 2026 10:50:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D0=B9=20=D1=81?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=D0=BE=D0=BA=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7?= =?UTF-8?q?=20git?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 40 ++++++++++++++++++++++++++++------------ debian/control | 2 +- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 4dfa006..73c86c0 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Makefile для GPIO Monitor Server -.PHONY: all build clean run test fmt lint help install dev deb prepare-debian +.PHONY: all build clean run test fmt lint help install dev deb prepare-debian version deb-clean deb-info deb-contents # Переменные APP_NAME := gpio-monitor-server @@ -15,6 +15,13 @@ DEB_PACKAGE := $(DEB_DIR)/$(APP_NAME) GOOS ?= linux GOARCH ?= arm64 +# Версионирование DEB пакета +BASE_VERSION := $(shell awk '/^Version:/ {print $$2; exit}' $(DEB_DIR)/control 2>/dev/null) +BASE_VERSION := $(if $(BASE_VERSION),$(BASE_VERSION),1.0.0) +GIT_COMMIT_COUNT := $(shell git rev-list --count HEAD 2>/dev/null || echo 0) +DEB_VERSION := $(BASE_VERSION)-build$(GIT_COMMIT_COUNT) +DEB_FILENAME := $(APP_NAME)_$(DEB_VERSION)_$(GOARCH).deb + # Флаги сборки LDFLAGS := -ldflags="-s -w" @@ -163,7 +170,9 @@ prepare-debian: @mkdir -p $(DEB_PACKAGE)/etc/gpio-monitoring @mkdir -p $(DEB_PACKAGE)/etc/systemd/system @# Копируем DEBIAN файлы - @if [ -f $(DEB_DIR)/control ]; then cp $(DEB_DIR)/control $(DEB_PACKAGE)/DEBIAN/; fi + @sed -e 's/^Version:.*/Version: $(DEB_VERSION)/' \ + -e 's/^Architecture:.*/Architecture: $(GOARCH)/' \ + $(DEB_DIR)/control > $(DEB_PACKAGE)/DEBIAN/control @if [ -f $(DEB_DIR)/preinst ]; then cp $(DEB_DIR)/preinst $(DEB_PACKAGE)/DEBIAN/; fi @if [ -f $(DEB_DIR)/postinst ]; then cp $(DEB_DIR)/postinst $(DEB_PACKAGE)/DEBIAN/; fi @if [ -f $(DEB_DIR)/prerm ]; then cp $(DEB_DIR)/prerm $(DEB_PACKAGE)/DEBIAN/; fi @@ -176,6 +185,7 @@ prepare-debian: fi @# Устанавливаем права @chmod 755 $(DEB_PACKAGE)/DEBIAN/* 2>/dev/null || true + @chmod 644 $(DEB_PACKAGE)/DEBIAN/control $(DEB_PACKAGE)/DEBIAN/md5sums 2>/dev/null || true @echo "$(GREEN)Структура подготовлена$(NC)" ## deb - Сборка DEB пакета @@ -203,14 +213,13 @@ deb: clean build-frontend build-backend prepare-debian @# Создаем архив с контрольными суммами @cd $(DEB_PACKAGE) && find . -type f ! -path "./DEBIAN/*" -exec md5sum {} \; > DEBIAN/md5sums 2>/dev/null || true @# Собираем пакет - @dpkg-deb --root-owner-group --build $(DEB_PACKAGE) . @mkdir -p $(BUILD_DIR) - @mv *.deb $(BUILD_DIR)/ - @echo "$(GREEN)DEB пакет создан: $(BUILD_DIR)/$(APP_NAME).deb$(NC)" - @ls -lh $(BUILD_DIR)/*.deb + @dpkg-deb --root-owner-group --build $(DEB_PACKAGE) $(BUILD_DIR)/$(DEB_FILENAME) + @echo "$(GREEN)DEB пакет создан: $(BUILD_DIR)/$(DEB_FILENAME)$(NC)" + @ls -lh $(BUILD_DIR)/$(DEB_FILENAME) @echo "" @echo "$(GREEN)Информация о пакете:$(NC)" - @dpkg-deb -I $(BUILD_DIR)/*.deb | head -15 + @dpkg-deb -I $(BUILD_DIR)/$(DEB_FILENAME) | head -15 # ============================================ # ДОПОЛНИТЕЛЬНЫЕ ЦЕЛИ @@ -246,25 +255,32 @@ docker-run: @echo "$(YELLOW)Запуск в Docker...$(NC)" @docker run -p 8080:8080 gpio-monitor:latest +## version - Показать вычисленную версию и имя deb-пакета +version: + @echo "BASE_VERSION: $(BASE_VERSION)" + @echo "GIT_COMMIT_COUNT: $(GIT_COMMIT_COUNT)" + @echo "DEB_VERSION: $(DEB_VERSION)" + @echo "DEB_FILENAME: $(DEB_FILENAME)" + ## deb-clean - Очистка временных файлов deb-пакета deb-clean: @echo "$(YELLOW)Очистка deb-временных файлов...$(NC)" @rm -rf $(DEB_PACKAGE) - @rm -f $(BUILD_DIR)/$(APP_NAME).deb + @rm -f $(BUILD_DIR)/$(APP_NAME)_*.deb @echo "$(GREEN)Очищено$(NC)" ## deb-info - Показать информацию о deb-пакете deb-info: - @if [ -f "$(BUILD_DIR)/$(APP_NAME).deb" ]; then \ - dpkg-deb -I $(BUILD_DIR)/$(APP_NAME).deb; \ + @if [ -f "$(BUILD_DIR)/$(DEB_FILENAME)" ]; then \ + dpkg-deb -I $(BUILD_DIR)/$(DEB_FILENAME); \ else \ echo "$(RED)Пакет не найден. Сначала выполните: make deb$(NC)"; \ fi ## deb-contents - Показать содержимое deb-пакета deb-contents: - @if [ -f "$(BUILD_DIR)/$(APP_NAME).deb" ]; then \ - dpkg-deb -c $(BUILD_DIR)/$(APP_NAME).deb; \ + @if [ -f "$(BUILD_DIR)/$(DEB_FILENAME)" ]; then \ + dpkg-deb -c $(BUILD_DIR)/$(DEB_FILENAME); \ else \ echo "$(RED)Пакет не найден. Сначала выполните: make deb$(NC)"; \ fi diff --git a/debian/control b/debian/control index 959489e..6af889c 100644 --- a/debian/control +++ b/debian/control @@ -6,7 +6,7 @@ Build-Depends: debhelper (>= 11), dh-golang, golang-go, npm Standards-Version: 4.5.0 Homepage: https://example.com/gpio-monitor Package: gpio-monitor-server -Version: 1.0.0-1 +Version: 1.0.0 Architecture: arm64 Depends: systemd Description: GPIO Monitor Server