Skip to content

Commit

Permalink
Merge pull request #31 from anchore/update-version-info
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleyjones committed Mar 9, 2023
2 parents b03aa54 + 42a5a39 commit 04f11e8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ builds:
-X github.com/anchore/anchore-ecs-inventory/internal/version.version={{.Version}}
-X github.com/anchore/anchore-ecs-inventory/internal/version.gitCommit={{.Commit}}
-X github.com/anchore/anchore-ecs-inventory/internal/version.buildDate={{.Date}}
# -X github.com/anchore/anchore-ecs-inventory/internal/version.gitTreeState={{.Env.BUILD_GIT_TREE_STATE}}
-X github.com/anchore/anchore-ecs-inventory/internal/version.gitDescription={{.Summary}}
archives:
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func printVersion(_ *cobra.Command, _ []string) {
fmt.Println("Version: ", versionInfo.Version)
fmt.Println("BuildDate: ", versionInfo.BuildDate)
fmt.Println("GitCommit: ", versionInfo.GitCommit)
fmt.Println("GitTreeState: ", versionInfo.GitTreeState)
fmt.Println("GitDescription: ", versionInfo.GitDescription)
fmt.Println("Platform: ", versionInfo.Platform)
fmt.Println("GoVersion: ", versionInfo.GoVersion)
fmt.Println("Compiler: ", versionInfo.Compiler)
Expand Down
40 changes: 21 additions & 19 deletions internal/version/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,33 @@ import (

const valueNotProvided = "[not provided]"

var version = valueNotProvided
var gitCommit = valueNotProvided
var gitTreeState = valueNotProvided
var buildDate = valueNotProvided
var platform = fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
var (
version = valueNotProvided
gitCommit = valueNotProvided
gitDescription = valueNotProvided
buildDate = valueNotProvided
platform = fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
)

type Version struct {
Version string `json:"version"`
GitCommit string `json:"gitCommit"`
GitTreeState string `json:"gitTreeState"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
Version string `json:"version"`
GitCommit string `json:"gitCommit"` // git SHA at build time
GitDescription string `json:"gitDescription"` // output of 'git describe --dirty --always --tags'
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
}

// Return version object (created or not during build)
func FromBuild() Version {
return Version{
Version: version,
GitCommit: gitCommit,
GitTreeState: gitTreeState,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: platform,
Version: version,
GitCommit: gitCommit,
GitDescription: gitDescription,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: platform,
}
}
2 changes: 1 addition & 1 deletion internal/version/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestFromBuild(t *testing.T) {
assert.Equal(t, valueNotProvided, version.Version)
assert.Equal(t, valueNotProvided, version.GitCommit)
assert.Equal(t, valueNotProvided, version.BuildDate)
assert.Equal(t, valueNotProvided, version.GitTreeState)
assert.Equal(t, valueNotProvided, version.GitDescription)
assert.Equal(t, runtime.Version(), version.GoVersion)
assert.Equal(t, runtime.Compiler, version.Compiler)
assert.Equal(t, fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), version.Platform)
Expand Down

0 comments on commit 04f11e8

Please sign in to comment.