From 4baf0e494497fa7d482bab0d465baee597ff069f Mon Sep 17 00:00:00 2001 From: marston Date: Tue, 25 Jun 2024 16:15:38 -0400 Subject: [PATCH] adding version details --- Makefile | 8 +++++++- api/index.go | 5 ++++- api/types/responses.go | 1 + cmd/root.go | 16 +++++++++++++++- config/version.go | 20 ++++++++++++++++++++ 5 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 config/version.go diff --git a/Makefile b/Makefile index f475a36..8517452 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,19 @@ export GO111MODULE = on +VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//') +COMMIT := $(shell git log -1 --format='%H') + ############################################################################### ### All ### ############################################################################### +ldflags = -X github.com/JackalLabs/sequoia/config.COMMIT=$(COMMIT) \ + -X github.com/JackalLabs/sequoia/config.VERSION=$(VERSION) + all: lint test-unit install: - @go install + @go install -ldflags '$(ldflags)' .PHONY: install diff --git a/api/index.go b/api/index.go index d952aba..2fb0bd8 100644 --- a/api/index.go +++ b/api/index.go @@ -3,6 +3,8 @@ package api import ( "net/http" + "github.com/JackalLabs/sequoia/config" + "github.com/JackalLabs/sequoia/api/types" "github.com/desmos-labs/cosmos-go-wallet/wallet" "github.com/rs/zerolog/log" @@ -32,7 +34,8 @@ func VersionHandler(wallet *wallet.Wallet) func(http.ResponseWriter, *http.Reque } v := types.VersionResponse{ - Version: "1.1.0-lite", + Version: config.Version(), + Commit: config.Commit(), ChainID: chainId, } diff --git a/api/types/responses.go b/api/types/responses.go index 56d9c40..df1b9be 100644 --- a/api/types/responses.go +++ b/api/types/responses.go @@ -13,6 +13,7 @@ type ErrorResponse struct { type VersionResponse struct { Version string `json:"version"` + Commit string `json:"build"` ChainID string `json:"chain-id"` } diff --git a/cmd/root.go b/cmd/root.go index 6a31c5f..0ddf033 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -46,6 +46,20 @@ func InitCmd() *cobra.Command { return r } +func VersionCmd() *cobra.Command { + r := &cobra.Command{ + Use: "version", + Short: "checks the version of sequoia", + RunE: func(cmd *cobra.Command, args []string) error { + fmt.Printf("Version: %s\nCommit: %s\n", config.Version(), config.Commit()) + + return nil + }, + } + + return r +} + func RootCmd() *cobra.Command { r := &cobra.Command{ Use: "sequoia", @@ -54,7 +68,7 @@ func RootCmd() *cobra.Command { r.PersistentFlags().String(types.FlagHome, types.DefaultHome, "sets the home directory for sequoia") - r.AddCommand(StartCmd(), wallet.WalletCmd(), InitCmd()) + r.AddCommand(StartCmd(), wallet.WalletCmd(), InitCmd(), VersionCmd()) return r } diff --git a/config/version.go b/config/version.go new file mode 100644 index 0000000..c02e9ef --- /dev/null +++ b/config/version.go @@ -0,0 +1,20 @@ +package config + +var ( + VERSION string + COMMIT string +) + +func Version() string { + if len(VERSION) == 0 { + return "0.0.0" + } + return VERSION +} + +func Commit() string { + if len(COMMIT) == 0 { + return "N/A" + } + return COMMIT +}