Skip to content

Commit

Permalink
Merge pull request #45 from heetch/put-version
Browse files Browse the repository at this point in the history
Use Main.Version to put the versioning
  • Loading branch information
sixstone-qq committed Apr 7, 2022
2 parents e29b183 + 427502f commit 3583cc6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 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
14 changes: 12 additions & 2 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ package main
import (
"flag"
"fmt"
"runtime/debug"
)

const AppVersion = "v0.2.0"
var Version string

type versionCmd struct{}

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

Expand Down

0 comments on commit 3583cc6

Please sign in to comment.