[add] YAO CMD PRVERSION Support

This commit is contained in:
Max 2022-06-09 18:18:40 +08:00
parent be4fc68c05
commit 33ae449cd9
3 changed files with 42 additions and 2 deletions

View file

@ -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

View file

@ -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)
},
}

View file

@ -3,6 +3,9 @@ package share
// VERSION 版本号
const VERSION = "0.9.2"
// PRVERSION PreRelease Version
const PRVERSION = "DEV"
// BUILDIN 打包应用合成一个制品
const BUILDIN = false