From b8ac9649d73f8908f83d8a8c8aa16afa6b612e45 Mon Sep 17 00:00:00 2001 From: Tim <11543666+tbckr@users.noreply.github.com> Date: Wed, 22 Mar 2023 18:24:34 +0100 Subject: [PATCH] fix: Fixed build information in the CLI version command The commit fixes issue #17 by updating the build information in the CLI version command. The build information now includes the commit date and commit hash. The changes were made in the version.go and .goreleaser.yaml files. --- .goreleaser.yaml | 4 +++- cmd/sgpt/cli/version.go | 9 ++++++--- internal/buildinfo/version.go | 19 +++++++++++++++++++ sgpt.go | 1 - 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 internal/buildinfo/version.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml index af65da18..23fd5958 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -36,7 +36,9 @@ builds: - goos: windows goarch: arm ldflags: - - "-X 'sgpt.Version={{.Version}}'" + - -X 'github.com/tbckr/sgpt/internal/buildinfo.version={{.Version}}' + - -X 'github.com/tbckr/sgpt/internal/buildinfo.commit={{.Commit}}' + - -X 'github.com/tbckr/sgpt/internal/buildinfo.commitDate={{.CommitDate}}' archives: - format: tar.gz diff --git a/cmd/sgpt/cli/version.go b/cmd/sgpt/cli/version.go index ec483b96..d71b2524 100644 --- a/cmd/sgpt/cli/version.go +++ b/cmd/sgpt/cli/version.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/peterbourgon/ff/v3/ffcli" - "github.com/tbckr/sgpt" + "github.com/tbckr/sgpt/internal/buildinfo" ) var versionCmd = &ffcli.Command{ @@ -34,7 +34,9 @@ func runVersion(_ context.Context, _ []string) error { var output string if versionArgs.json { versionMap := map[string]string{ - "version": sgpt.Version, + "version": buildinfo.Version(), + "commit": buildinfo.Commit(), + "commitDate": buildinfo.CommitDate(), } byteData, err := json.Marshal(versionMap) if err != nil { @@ -42,7 +44,8 @@ func runVersion(_ context.Context, _ []string) error { } output = string(byteData) } else { - output = sgpt.Version + output = fmt.Sprintf("version: %s\ncommit: %s\ncommitDate: %s", + buildinfo.Version(), buildinfo.Commit(), buildinfo.CommitDate()) } if _, err := fmt.Fprintln(stdout, output); err != nil { return err diff --git a/internal/buildinfo/version.go b/internal/buildinfo/version.go new file mode 100644 index 00000000..3187ef0f --- /dev/null +++ b/internal/buildinfo/version.go @@ -0,0 +1,19 @@ +package buildinfo + +var ( + version = "dev" + commit = "unset" + commitDate = "unset" +) + +func Version() string { + return version +} + +func Commit() string { + return commit +} + +func CommitDate() string { + return commitDate +} diff --git a/sgpt.go b/sgpt.go index 8aab7a3b..973f2d5b 100644 --- a/sgpt.go +++ b/sgpt.go @@ -22,7 +22,6 @@ var ( ErrMissingAPIKey = fmt.Errorf("%s env variable is not set", envKeyOpenAIApi) ErrUnsupportedModifier = errors.New("unsupported modifier") ErrChatNotSupported = errors.New("chat is not supported with this model") - Version = "dev" ) type CompletionOptions struct {