Skip to content

Commit 6e87391

Browse files
committed
Read binary version using BuildInfo
1 parent d953d42 commit 6e87391

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

Makefile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,10 @@ GO_FILES := $(shell find . -type f \( -iname '*.go' \))
33

44
SCRIPT_FILES := $(wildcard ./bin/*)
55

6-
HE_BUILD_VERSION ?= $(shell git describe --tags)
7-
ifeq ($(HE_BUILD_VERSION),)
8-
_ := $(error Cannot determine build version)
9-
endif
10-
11-
BUILD_VERSION_FLAG := github.com/eikendev/hackenv/internal/buildconfig.Version=$(HE_BUILD_VERSION)
12-
136
.PHONY: build
147
build:
158
mkdir -p $(OUT_DIR)
16-
go build -ldflags "-w -s -X $(BUILD_VERSION_FLAG)" -o $(OUT_DIR)/hackenv ./cmd/hackenv
9+
go build -ldflags "-w -s" -o $(OUT_DIR)/hackenv ./cmd/hackenv
1710

1811
.PHONY: clean
1912
clean:

internal/commands/version.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package commands
33

44
import (
55
"fmt"
6+
"runtime/debug"
67

7-
"github.com/eikendev/hackenv/internal/buildconfig"
88
"github.com/eikendev/hackenv/internal/options"
99
)
1010

@@ -13,7 +13,11 @@ type VersionCommand struct{}
1313

1414
// Run is the function for the version command.
1515
func (*VersionCommand) Run(_ *options.Options) error {
16-
fmt.Printf("hackenv %s\n", buildconfig.Version)
16+
buildInfo, ok := debug.ReadBuildInfo()
17+
if !ok {
18+
return fmt.Errorf("build info not available")
19+
}
1720

21+
fmt.Printf("hackenv %s\n", buildInfo.Main.Version)
1822
return nil
1923
}

0 commit comments

Comments
 (0)