Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

feat: add version command #565

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/make -f

VERSION := $(shell echo $(shell git describe --tags 2>/dev/null || git log -1 --format='%h') | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
DOCKER := $(shell which docker)
versioningPath := "github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/version"
LDFLAGS=-ldflags="-X '$(versioningPath).buildTime=$(shell date)' -X '$(versioningPath).lastCommit=$(shell git rev-parse HEAD)' -X '$(versioningPath).semanticVersion=$(shell git describe --tags --dirty=-dev 2>/dev/null || git rev-parse --abbrev-ref HEAD)'"

all: install

install: go.sum
@echo "--> Installing blobstream"
@go install -mod=readonly ./cmd/blobstream
@go install -mod=readonly ${LDFLAGS} ./cmd/blobstream

go.sum: mod
@echo "--> Verifying dependencies have expected content"
Expand All @@ -24,7 +25,7 @@ pre-build:

build: mod
@mkdir -p build/
@go build -o build ./cmd/blobstream
@go build -o build ${LDFLAGS} ./cmd/blobstream

build-docker:
@echo "--> Building Docker image"
Expand Down
2 changes: 2 additions & 0 deletions cmd/blobstream/root/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/bootstrapper"
"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/generate"
"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/query"
"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/version"

"github.com/celestiaorg/celestia-app/x/qgb/client"
"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/deploy"
Expand All @@ -30,6 +31,7 @@ func Cmd() *cobra.Command {
generate.Command(),
query.Command(),
bootstrapper.Command(),
version.Cmd,
)

rootCmd.SetHelpCommand(&cobra.Command{})
Expand Down
35 changes: 35 additions & 0 deletions cmd/blobstream/version/build_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package version

import (
"fmt"
"runtime"
)

var (
buildTime string
lastCommit string
semanticVersion string

systemVersion = fmt.Sprintf("%s/%s", runtime.GOARCH, runtime.GOOS)
golangVersion = runtime.Version()
)

// BuildInfo represents all necessary information about the current build.
type BuildInfo struct {
BuildTime string
LastCommit string
SemanticVersion string
SystemVersion string
GolangVersion string
}

// GetBuildInfo returns information about the current build.
func GetBuildInfo() *BuildInfo {
return &BuildInfo{
buildTime,
lastCommit,
semanticVersion,
systemVersion,
golangVersion,
}
}
23 changes: 23 additions & 0 deletions cmd/blobstream/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package version

import (
"fmt"

"github.com/spf13/cobra"
)

var Cmd = &cobra.Command{
Use: "version",
Short: "Show information about the current binary build",
Args: cobra.NoArgs,
Run: printBuildInfo,
}

func printBuildInfo(_ *cobra.Command, _ []string) {
buildInfo := GetBuildInfo()
fmt.Printf("Semantic version: %s\n", buildInfo.SemanticVersion)
fmt.Printf("Commit: %s\n", buildInfo.LastCommit)
fmt.Printf("Build Date: %s\n", buildInfo.BuildTime)
fmt.Printf("System version: %s\n", buildInfo.SystemVersion)
fmt.Printf("Golang version: %s\n", buildInfo.GolangVersion)
}
Loading