Skip to content

Commit

Permalink
Merge pull request #49 from JackalLabs/marston/versions
Browse files Browse the repository at this point in the history
adding version details
  • Loading branch information
dahn510 authored Jun 26, 2024
2 parents 1aa3eb7 + 4baf0e4 commit 74294dd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 4 additions & 1 deletion api/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}

Expand Down
1 change: 1 addition & 0 deletions api/types/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ErrorResponse struct {

type VersionResponse struct {
Version string `json:"version"`
Commit string `json:"build"`
ChainID string `json:"chain-id"`
}

Expand Down
16 changes: 15 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
}
Expand Down
20 changes: 20 additions & 0 deletions config/version.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 74294dd

Please sign in to comment.