optimize Makefile

pull/393/head
Michael Li 1 year ago
parent 2c353ca9ad
commit dcc10ee87d
No known key found for this signature in database

@ -18,15 +18,16 @@ RELEASE_DARWIN_AMD64 = $(RELEASE_ROOT)/darwin-amd64/$(PROJECT)
RELEASE_DARWIN_ARM64 = $(RELEASE_ROOT)/darwin-arm64/$(PROJECT) RELEASE_DARWIN_ARM64 = $(RELEASE_ROOT)/darwin-arm64/$(PROJECT)
RELEASE_WINDOWS_AMD64 = $(RELEASE_ROOT)/windows-amd64/$(PROJECT) RELEASE_WINDOWS_AMD64 = $(RELEASE_ROOT)/windows-amd64/$(PROJECT)
BUILD_VERSION := $(shell git describe --tags --always | cut -f 1 -f 2 -d "-") BUILD_VERSION := $(shell git describe --tags --always)
BUILD_DATE := $(shell date +'%Y-%m-%d %H:%M:%S') BUILD_DATE := $(shell date +'%Y-%m-%d %H:%M:%S %Z')
SHA_SHORT := $(shell git rev-parse --short HEAD) SHA_SHORT := $(shell git rev-parse --short HEAD)
TAGS = ""
MOD_NAME = github.com/rocboss/paopao-ce MOD_NAME = github.com/rocboss/paopao-ce
LDFLAGS = -X "${MOD_NAME}/pkg/version.version=${BUILD_VERSION}" \ LDFLAGS = -X "${MOD_NAME}/pkg/version.version=${BUILD_VERSION}" \
-X "${MOD_NAME}/pkg/version.buildDate=${BUILD_DATE}" \ -X "${MOD_NAME}/pkg/version.buildDate=${BUILD_DATE}" \
-X "${MOD_NAME}/pkg/version.commitID=${SHA_SHORT}" -w -s -X "${MOD_NAME}/pkg/version.commitID=${SHA_SHORT}" \
-X "${MOD_NAME}/pkg/version.buildTags=${TAGS}" \
-w -s
all: fmt build all: fmt build

@ -2,7 +2,7 @@
# eg.1 : sh build-image.sh # eg.1 : sh build-image.sh
# eg.2, set image: sh build-image.sh bitbus/paopao-ce # eg.2, set image: sh build-image.sh bitbus/paopao-ce
VERSION=`git describe --tags --always | cut -f1 -f2 -d "-"` # eg.: 0.2.5 VERSION=`git describe --tags --always | cut -f1,2 -d "-"` # eg.: 0.2.5
IMAGE="bitbus/paopao-ce" IMAGE="bitbus/paopao-ce"
if [ -n "$1" ]; then if [ -n "$1" ]; then

@ -8,25 +8,35 @@ import (
"fmt" "fmt"
) )
var version, commitID, buildDate string const (
series = "v0.5.0-dev"
)
var (
version = "unknown"
commitID = "unknown"
buildDate = "unknown"
buildTags = "unknown"
)
type BuildInfo struct { type BuildInfo struct {
Series string `json:"series"`
Version string `json:"version"` Version string `json:"version"`
Sum string `json:"sum"` Sum string `json:"sum"`
BuildDate string `json:"build_date"` BuildDate string `json:"build_date"`
BuildTags string `json:"build_tags"`
} }
func VersionInfo() string { func VersionInfo() string {
return fmt.Sprintf("paopao %s (build:%s %s)", version, commitID, buildDate) return fmt.Sprintf("paopao %s (build:%s %s)", series, commitID, buildDate)
} }
func ReadBuildInfo() *BuildInfo { func ReadBuildInfo() *BuildInfo {
if version == "" {
version = "unknow"
}
return &BuildInfo{ return &BuildInfo{
Series: series,
Version: version, Version: version,
Sum: commitID, Sum: commitID,
BuildDate: buildDate, BuildDate: buildDate,
BuildTags: buildTags,
} }
} }

Loading…
Cancel
Save