From 9a176c75a65f58005b64231667f73fe06f4ca31d Mon Sep 17 00:00:00 2001 From: xiaochenl Date: Mon, 26 Apr 2021 11:07:57 +0800 Subject: [PATCH] fix(ci):get app_version automatically get app_version automatically --- Makefile | 8 ++++++-- scripts/release_binary.sh | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index aac5f71..19af2eb 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,6 @@ SHELL := /bin/bash CURRENT_PATH = $(shell pwd) APP_NAME = bitxhub -APP_VERSION = 1.6.0 export GODEBUG=x509ignoreCN=0 # build with verison infos @@ -10,6 +9,11 @@ VERSION_DIR = github.com/meshplus/${APP_NAME} BUILD_DATE = $(shell date +%FT%T) GIT_COMMIT = $(shell git log --pretty=format:'%h' -n 1) GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD) +ifeq (${GIT_BRANCH},HEAD) + APP_VERSION = $(shell git describe --tags HEAD) +else + APP_VERSION = dev +endif GOLDFLAGS += -X "${VERSION_DIR}.BuildDate=${BUILD_DATE}" GOLDFLAGS += -X "${VERSION_DIR}.CurrentCommit=${GIT_COMMIT}" @@ -83,7 +87,7 @@ buildent: ## make release: Build release before push release-binary: - @cd scripts && bash release_binary.sh '${APP_VERSION}' + @cd scripts && bash release_binary.sh mod: sed "s?)?$(MODS)\n)?" go.mod diff --git a/scripts/release_binary.sh b/scripts/release_binary.sh index 465483a..cf1c37c 100644 --- a/scripts/release_binary.sh +++ b/scripts/release_binary.sh @@ -5,7 +5,8 @@ source x.sh CURRENT_PATH=$(pwd) PROJECT_PATH=$(dirname "${CURRENT_PATH}") BUILD_PATH=${PROJECT_PATH}/build -APP_VERSION=${1:-'1.6.0'} +# shellcheck disable=SC2046 +APP_VERSION=$(if [ `git rev-parse --abbrev-ref HEAD` == 'HEAD' ];then git describe --tags HEAD ; else echo "dev" ; fi) print_blue "===> 1. Install packr" if ! type packr >/dev/null 2>&1; then