From c64df2c9844cf7a00957891a5ae960d092394999 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 1 Feb 2023 16:36:02 +0000 Subject: [PATCH] Report version correctly (#97) --- cmd/hc-install/main.go | 4 ++-- internal/httpclient/httpclient.go | 4 ++-- internal/version/version.go | 9 --------- version/VERSION | 1 + version/version.go | 20 ++++++++++++++++++++ 5 files changed, 25 insertions(+), 13 deletions(-) delete mode 100644 internal/version/version.go create mode 100644 version/VERSION create mode 100644 version/version.go diff --git a/cmd/hc-install/main.go b/cmd/hc-install/main.go index 13f8c7c..241a4db 100644 --- a/cmd/hc-install/main.go +++ b/cmd/hc-install/main.go @@ -4,7 +4,7 @@ import ( "log" "os" - "github.com/hashicorp/hc-install/internal/version" + "github.com/hashicorp/hc-install/version" "github.com/hashicorp/logutils" "github.com/mitchellh/cli" @@ -28,7 +28,7 @@ func main() { }, } - c := cli.NewCLI("hc-install", version.ModuleVersion()) + c := cli.NewCLI("hc-install", version.Version().String()) c.Args = os.Args[1:] c.Commands = map[string]cli.CommandFactory{ "install": func() (cli.Command, error) { diff --git a/internal/httpclient/httpclient.go b/internal/httpclient/httpclient.go index 159f705..0ae6ae4 100644 --- a/internal/httpclient/httpclient.go +++ b/internal/httpclient/httpclient.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/hashicorp/go-cleanhttp" - "github.com/hashicorp/hc-install/internal/version" + "github.com/hashicorp/hc-install/version" ) // NewHTTPClient provides a pre-configured http.Client @@ -13,7 +13,7 @@ import ( func NewHTTPClient() *http.Client { client := cleanhttp.DefaultClient() - userAgent := fmt.Sprintf("hc-install/%s", version.ModuleVersion()) + userAgent := fmt.Sprintf("hc-install/%s", version.Version()) cli := cleanhttp.DefaultPooledClient() cli.Transport = &userAgentRoundTripper{ diff --git a/internal/version/version.go b/internal/version/version.go deleted file mode 100644 index d8bc462..0000000 --- a/internal/version/version.go +++ /dev/null @@ -1,9 +0,0 @@ -package version - -const version = "0.1.0" - -// ModuleVersion returns the current version of the github.com/hashicorp/hc-install Go module. -// This is a function to allow for future possible enhancement using debug.BuildInfo. -func ModuleVersion() string { - return version -} diff --git a/version/VERSION b/version/VERSION new file mode 100644 index 0000000..5c73f2a --- /dev/null +++ b/version/VERSION @@ -0,0 +1 @@ +0.4.0-dev \ No newline at end of file diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000..db367e5 --- /dev/null +++ b/version/version.go @@ -0,0 +1,20 @@ +package version + +import ( + _ "embed" + + "github.com/hashicorp/go-version" +) + +//go:embed VERSION +var rawVersion string + +// Version returns the version of the library +// +// Note: This is only exposed as public function/package +// due to hard-coded constraints in the release tooling. +// In general downstream should not implement version-specific +// logic and rely on this function to be present in future releases. +func Version() *version.Version { + return version.Must(version.NewVersion(rawVersion)) +}