Skip to content

Commit

Permalink
automatically write version info every time release (alibaba#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cirilla-zmh authored Dec 3, 2024
1 parent f2db3ac commit 927a798
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
39 changes: 20 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@

#-------------------------------------------------------------------------------
# General build options
# Change this parameter while releasing
MAIN_VERSION := 0.4.0

CURRENT_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
CURRENT_ARCH := $(shell uname -m)

MOD_NAME := github.com/alibaba/opentelemetry-go-auto-instrumentation
VERSION := $(MAIN_VERSION)_$(COMMIT_ID)
XVERSION := -X=$(MOD_NAME)/tool/config.ToolVersion=$(VERSION)
STRIP_DEBUG := -s -w
LDFLAGS := $(XVERSION) $(STRIP_DEBUG)
BUILD_CMD = CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build -a -ldflags="$(LDFLAGS)" -o $(3) ./tool/cmd
# default build cmd without ldflags
BUILD_CMD = CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build -a -o $(3) ./tool/cmd

OUTPUT_BASE = otel
OUTPUT_DARWIN_AMD64 = $(OUTPUT_BASE)-darwin-amd64
Expand All @@ -31,6 +33,21 @@ OUTPUT_WINDOWS_AMD64 = $(OUTPUT_BASE)-windows-amd64.exe
OUTPUT_DARWIN_ARM64 = $(OUTPUT_BASE)-darwin-arm64
OUTPUT_LINUX_ARM64 = $(OUTPUT_BASE)-linux-arm64

#-------------------------------------------------------------------------------
# Prepare version
# Get the current Git commit ID
CHECK_GIT_DIRECTORY := $(if $(wildcard .git),true,false)
ifeq ($(CHECK_GIT_DIRECTORY),true)
COMMIT_ID := $(shell git rev-parse --short HEAD)
else
COMMIT_ID := default
endif

VERSION := $(MAIN_VERSION)_$(COMMIT_ID)
XVERSION := -X=$(MOD_NAME)/tool/config.ToolVersion=$(VERSION) -X=$(MOD_NAME)/pkg/inst-api/version.Tag=v$(VERSION)
LDFLAGS := $(XVERSION) $(STRIP_DEBUG)
BUILD_CMD = CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build -a -ldflags="$(LDFLAGS)" -o $(3) ./tool/cmd

#-------------------------------------------------------------------------------
# Multiple OS and ARCH support
ifeq ($(CURRENT_ARCH), x86_64)
Expand All @@ -46,22 +63,6 @@ ifeq ($(findstring msys,$(CURRENT_OS)),msys)
CURRENT_OS := windows
endif

# Get the current Git commit ID
CHECK_GIT_DIRECTORY := $(if $(wildcard .git),true,false)
ifeq ($(CHECK_GIT_DIRECTORY),true)
BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD)
ifeq ($(findstring /,$(BRANCH_NAME)),/)
MAIN_VERSION := $(shell echo $(BRANCH_NAME) | cut -d'/' -f2-)
else
MAIN_VERSION := 1.0.0
endif
COMMIT_ID := $(shell git rev-parse --short HEAD)
else
BRANCH_NAME := 1.0.0
MAIN_VERSION := 1.0.0
COMMIT_ID := default
endif

#-------------------------------------------------------------------------------
# Build targets
.PHONY: build
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/elastic/elastic-transport-go/v8 v8.0.0-alpha h1:SW9xcMVxx4Nv9oRm5rQxzAMAatwiZV8xROP2a48y45Q=
github.com/elastic/elastic-transport-go/v8 v8.0.0-alpha/go.mod h1:87Tcz8IVNe6rVSLdBux1o/PEItLtyabHU3naC7IoqKI=
github.com/elastic/elastic-transport-go/v8 v8.1.0 h1:NeqEz1ty4RQz+TVbUrpSU7pZ48XkzGWQj02k5koahIE=
github.com/elastic/elastic-transport-go/v8 v8.1.0/go.mod h1:87Tcz8IVNe6rVSLdBux1o/PEItLtyabHU3naC7IoqKI=
github.com/elastic/go-elasticsearch/v8 v8.0.0 h1:Hte+pgoEZI88j/sQx7u9vK9SqisvJYkYMmxDnQXiJyM=
github.com/elastic/go-elasticsearch/v8 v8.0.0/go.mod h1:8NCWP26meGbncX+R9sxo2JD8IqBjRTuS7yXMstHpd40=
github.com/elastic/go-elasticsearch/v8 v8.4.0 h1:Rn1mcqaIMcNT43hnx2H62cIFZ+B6mjWtzj85BDKrvCE=
github.com/elastic/go-elasticsearch/v8 v8.4.0/go.mod h1:yY52i2Vj0unLz+N3Nwx1gM5LXwoj3h2dgptNGBYkMLA=
github.com/envoyproxy/go-control-plane v0.13.0 h1:HzkeUz1Knt+3bK+8LG1bxOO/jzWZmdxpwC51i202les=
github.com/envoyproxy/go-control-plane v0.13.0/go.mod h1:GRaKG3dwvFoTg4nj7aXdZnvMg4d7nvT/wl9WgVXn3Q8=
Expand Down
2 changes: 1 addition & 1 deletion pkg/inst-api/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
package version

// Tag specifies the current release tag. It needs to be manually updated.
const Tag = "v0.4.0"
var Tag = "v0.4.0"
2 changes: 1 addition & 1 deletion tool/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func InitConfig() (err error) {
}

func PrintVersion() error {
fmt.Printf("%s version %s", GetToolName(), ToolVersion)
fmt.Printf("%s version %s\n", GetToolName(), ToolVersion)
os.Exit(0)
return nil
}
Expand Down

0 comments on commit 927a798

Please sign in to comment.