diff --git a/Makefile b/Makefile index 338c84f1..abcea79b 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,11 @@ GO ?= go +GIT ?= git GOFMT ?= gofmt "-s" PACKAGES ?= $(shell $(GO) list ./...) VETPACKAGES ?= $(shell $(GO) list ./... | grep -v /examples/) GOFILES := $(shell find . -name "*.go") VERSION := $(shell grep 'const VERSION =' share/const.go |awk '{print $$4}' |sed 's/\"//g') +COMMIT := $(shell git log | head -n 1 | awk '{print substr($$2, 0, 12)}') # ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) TESTFOLDER := $(shell $(GO) list ./... | grep -vE 'examples|tests*|config') @@ -131,6 +133,9 @@ artifacts-linux: clean rm -rf .tmp/data rm -rf .tmp/ui +# Replace PRVERSION + sed -ie "s/const PRVERSION = \"DEV\"/const PRVERSION = \"${COMMIT}\"/g" share/const.go + # Making artifacts mkdir -p dist CGO_ENABLED=1 CGO_LDFLAGS="-static" GOOS=linux GOARCH=amd64 go build -v -o dist/yao-${VERSION}-linux-amd64 @@ -142,6 +147,10 @@ artifacts-linux: clean ls -l dist/release/ dist/release/yao-${VERSION}-linux-amd64 version +# Reset const +# cp -f share/const.goe share/const.go +# rm -f share/const.goe + # make artifacts-macos .PHONY: artifacts-macos artifacts-macos: clean @@ -159,6 +168,9 @@ artifacts-macos: clean rm -rf .tmp/data rm -rf .tmp/ui +# Replace PRVERSION + sed -ie "s/const PRVERSION = \"DEV\"/const PRVERSION = \"${COMMIT}\"/g" share/const.go + # Making artifacts mkdir -p dist CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -v -o dist/yao-${VERSION}-darwin-amd64 @@ -170,6 +182,10 @@ artifacts-macos: clean ls -l dist/release/ dist/release/yao-${VERSION}-darwin-amd64 version +# Reset const +# cp -f share/const.goe share/const.go +# rm -f share/const.goe + .PHONY: debug debug: clean mkdir -p dist/release @@ -181,11 +197,19 @@ debug: clean go-bindata -fs -pkg data -o data/bindata.go -prefix ".tmp/data/" .tmp/data/... rm -rf .tmp/data + +# Replace PRVERSION + sed -ie "s/const PRVERSION = \"DEV\"/const PRVERSION = \"${COMMIT}-debug\"/g" share/const.go + # Making artifacts mkdir -p dist CGO_ENABLED=1 go build -v -o dist/release/yao-debug chmod +x dist/release/yao-debug +# Reset const + cp -f share/const.goe share/const.go + rm -f share/const.goe + .PHONY: release release: clean mkdir -p dist/release @@ -194,7 +218,7 @@ release: clean # Building UI git clone https://github.com/YaoApp/xgen.git .tmp/ui sed -ie "s/url('\/icon/url('\/xiang\/icon/g" .tmp/ui/public/icon/md_icon.css - cd .tmp/ui && yarn install && yarn build + cd .tmp/ui && cnpm install && npm run build # Packing mkdir -p .tmp/data @@ -204,11 +228,18 @@ release: clean rm -rf .tmp/data rm -rf .tmp/ui +# Replace PRVERSION + sed -ie "s/const PRVERSION = \"DEV\"/const PRVERSION = \"${COMMIT}\"/g" share/const.go + # Making artifacts mkdir -p dist CGO_ENABLED=1 go build -v -o dist/release/yao chmod +x dist/release/yao +# Reset const + cp -f share/const.goe share/const.go + rm share/const.goe + .PHONY: linux-release linux-release: clean mkdir -p dist/release diff --git a/cmd/version.go b/cmd/version.go index 929bb829..5c7b4b26 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -12,7 +12,13 @@ var versionCmd = &cobra.Command{ Short: L("Show version"), Long: L("Show version"), Run: func(cmd *cobra.Command, args []string) { + + version := share.VERSION + if share.PRVERSION != "" { + version = fmt.Sprintf("%s-%s", share.VERSION, share.PRVERSION) + } + // Do Stuff Here - fmt.Println(share.VERSION) + fmt.Println(version) }, } diff --git a/share/const.go b/share/const.go index 3b0cc7fb..55424311 100644 --- a/share/const.go +++ b/share/const.go @@ -3,6 +3,9 @@ package share // VERSION 版本号 const VERSION = "0.9.2" +// PRVERSION PreRelease Version +const PRVERSION = "DEV" + // BUILDIN 打包应用合成一个制品 const BUILDIN = false