diff --git a/Makefile b/Makefile index 988c9cad5..63e424b84 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,12 @@ BUILD_FILES = $(shell go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}}\ {{end}}' ./...) -# export GOFLAGS := -mod=vendor $GOFLAGS +GH_VERSION = $(shell go describe --tags 2>/dev/null || git rev-parse --short HEAD) +LDFLAGS := -X github.com/github/gh-cli/command.Version=$(GH_VERSION) $(LDFLAGS) +LDFLAGS := -X github.com/github/gh-cli/command.BuildDate=$(shell date +%Y-%m-%d) $(LDFLAGS) bin/gh: $(BUILD_FILES) - go build -o "$@" + @go build -ldflags "$(LDFLAGS)" -o "$@" test: go test ./... diff --git a/command/root.go b/command/root.go index a309960e3..1e9c449b6 100644 --- a/command/root.go +++ b/command/root.go @@ -6,12 +6,18 @@ import ( "github.com/github/gh-cli/api" "github.com/github/gh-cli/context" - "github.com/github/gh-cli/version" "github.com/spf13/cobra" ) +// Version is dynamically set at build time in the Makefile +var Version = "DEV" + +// BuildDate is dynamically set at build time in the Makefile +var BuildDate = "YYYY-MM-DD" + func init() { + RootCmd.Version = fmt.Sprintf("%s (%s)", Version, BuildDate) RootCmd.PersistentFlags().StringP("repo", "R", "", "current GitHub repository") RootCmd.PersistentFlags().StringP("current-branch", "B", "", "current git branch") // TODO: @@ -65,7 +71,7 @@ var apiClientForContext = func(ctx context.Context) (*api.Client, error) { } opts := []api.ClientOption{ api.AddHeader("Authorization", fmt.Sprintf("token %s", token)), - api.AddHeader("User-Agent", fmt.Sprintf("GitHub CLI %s", version.Version)), + api.AddHeader("User-Agent", fmt.Sprintf("GitHub CLI %s", Version)), } if verbose := os.Getenv("DEBUG"); verbose != "" { opts = append(opts, api.VerboseLog(os.Stderr)) diff --git a/version/version.go b/version/version.go deleted file mode 100644 index 7314c51e6..000000000 --- a/version/version.go +++ /dev/null @@ -1,11 +0,0 @@ -package version - -import ( - "fmt" -) - -var Version = "0.0.0" - -func FullVersion() (string, error) { - return fmt.Sprintf("gh version %s", Version), nil -}