Skip to content

Commit

Permalink
Merge pull request #392 from sudo-bmitch/pr-build-version
Browse files Browse the repository at this point in the history
Include tag in the version output
  • Loading branch information
sudo-bmitch committed Mar 20, 2023
2 parents 02c525a + 99450cf commit 3ef593c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ifneq ($(shell git status --porcelain 2>/dev/null),)
endif
VCS_DATE?=$(shell date -d "@$(shell git log -1 --format=%at)" +%Y-%m-%dT%H:%M:%SZ --utc)
VCS_TAG?=$(shell git describe --tags --abbrev=0 2>/dev/null || true)
LD_FLAGS?=-s -w -extldflags -static -buildid=
LD_FLAGS?=-s -w -extldflags -static -buildid= -X \"github.com/regclient/regclient/internal/version.vcsTag=$(VCS_TAG)\"
GO_BUILD_FLAGS?=-trimpath -ldflags "$(LD_FLAGS)" -tags nolegacy
DOCKERFILE_EXT?=$(shell if docker build --help 2>/dev/null | grep -q -- '--progress'; then echo ".buildkit"; fi)
DOCKER_ARGS?=--build-arg "VCS_REF=$(VCS_REF)"
Expand Down
1 change: 1 addition & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
func (i Info) MarshalPretty() ([]byte, error) {
buf := &bytes.Buffer{}
tw := tabwriter.NewWriter(buf, 0, 0, 1, ' ', 0)
fmt.Fprintf(tw, "VCSTag:\t%s\n", i.VCSTag)
fmt.Fprintf(tw, "VCSRef:\t%s\n", i.VCSRef)
fmt.Fprintf(tw, "VCSCommit:\t%s\n", i.VCSCommit)
fmt.Fprintf(tw, "VCSState:\t%s\n", i.VCSState)
Expand Down
9 changes: 7 additions & 2 deletions internal/version/version_buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"time"
)

var vcsTag = ""

type Info struct {
GoVer string `json:"goVersion"` // go version
GoCompiler string `json:"goCompiler"` // go compiler
Expand All @@ -18,7 +20,7 @@ type Info struct {
VCSDate string `json:"vcsDate"` // commit date in RFC3339 format
VCSRef string `json:"vcsRef"` // commit sha + dirty if state is not clean
VCSState string `json:"vcsState"` // clean or dirty
VCSTag string `json:"-"` // tag is not available from Go
VCSTag string `json:"vcsTag"` // tag is not available from Go
Debug *debug.BuildInfo `json:"debug,omitempty"` // build info debugging data
}

Expand All @@ -30,7 +32,7 @@ func GetInfo() Info {
VCSDate: unknown,
VCSRef: unknown,
VCSState: unknown,
VCSTag: "",
VCSTag: vcsTag,
}

i.GoVer = runtime.Version()
Expand All @@ -39,6 +41,9 @@ func GetInfo() Info {

if bi, ok := debug.ReadBuildInfo(); ok && bi != nil {
i.Debug = bi
if i.VCSTag == "" {
i.VCSTag = bi.Main.Version
}
date := biSetting(bi, biVCSDate)
if t, err := time.Parse(time.RFC3339, date); err == nil {
i.VCSDate = t.UTC().Format(time.RFC3339)
Expand Down
2 changes: 1 addition & 1 deletion internal/version/version_old.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Info struct {
VCSDate string `json:"vcsDate"` // commit date in RFC3339 format
VCSRef string `json:"vcsRef"` // commit sha + dirty if state is not clean
VCSState string `json:"vcsState"` // clean or dirty
VCSTag string `json:"-"` // tag
VCSTag string `json:"vcsTag"` // tag
}

func GetInfo() Info {
Expand Down

0 comments on commit 3ef593c

Please sign in to comment.