Skip to content

Commit

Permalink
Provide Version from injected var if available
Browse files Browse the repository at this point in the history
  • Loading branch information
sixstone-qq committed Apr 7, 2022
1 parent 2ae908d commit 427502f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
VERSION=$(shell git describe --tags)

build:
go build
go build -ldflags="-X main.Version=$(VERSION)"

test:
go test
15 changes: 9 additions & 6 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import (
"runtime/debug"
)

const AppVersion = "v0.2.0"
var Version string

type versionCmd struct{}

func (cmd *versionCmd) run(args []string) error {
// TODO: Use Settings.VCS.Version from Go v1.18
version := "devel"
info, ok := debug.ReadBuildInfo()
if ok {
version = info.Main.Version
if Version == "" {
info, ok := debug.ReadBuildInfo()
if ok {
Version = info.Main.Version
} else {
Version = "devel"
}
}
fmt.Println("hkt version", version)
fmt.Println("hkt version", Version)
return nil
}

Expand Down

0 comments on commit 427502f

Please sign in to comment.