Skip to content

Commit

Permalink
Print protocol and contracts version in log (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht authored Dec 3, 2024
1 parent 73fcb4c commit 77eb70d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
16 changes: 7 additions & 9 deletions cmd/camino_messenger_bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@ import (

"github.com/chain4travel/camino-messenger-bot/config"
"github.com/chain4travel/camino-messenger-bot/internal/app"
"github.com/chain4travel/camino-messenger-bot/internal/version"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

var (
// these variables are set by go build -ldflags
// TODO: @VjeraTurk make this work when multiple bots are ran with launch.json
Version string
GitCommit string
)

var rootCmd = &cobra.Command{
Use: "camino-messenger-bot",
Short: "starts camino messenger bot",
Version: Version,
Version: version.AppVersion,
SuggestFor: []string{"camino-messenger", "camino-messenger-bot", "camino-bot", "cmb"},
RunE: rootFunc,
}
Expand Down Expand Up @@ -64,7 +58,11 @@ func rootFunc(cmd *cobra.Command, _ []string) error {
logger := zapLogger.Sugar()
defer func() { _ = logger.Sync() }()

logger.Infof("App version: %s (git: %s)", Version, GitCommit)
logger.Infof("App version: %s (git: %s)", version.AppVersion, version.AppGitCommit)
logger.Infof("Protocol version: %s", version.ProtocolVersion)
logger.Infof("buf.build protocolbuffers version: %s", version.BufBuildPBCommit)
logger.Infof("buf.build grpc version: %s", version.BufBuildGRPCCommit)
logger.Infof("camino-messenger-contracts version: %s", version.ContractsGitCommit)

app, err := app.NewApp(ctx, cfg, logger)
if err != nil {
Expand Down
31 changes: 31 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package version

import "runtime/debug"

const ProtocolVersion = "v10.0.0"

var (
// AppVersion is set by go build -ldflags
AppVersion = "Unspecified"

// AppGitCommit is set by go build -ldflags
AppGitCommit = "Unspecified"

BufBuildPBCommit = "Unspecified"
BufBuildGRPCCommit = "Unspecified"
ContractsGitCommit = "Unspecified"
)

func init() {
info, _ := debug.ReadBuildInfo()
for _, dependency := range info.Deps {
switch dependency.Path {
case "buf.build/gen/go/chain4travel/camino-messenger-protocol/protocolbuffers/go":
BufBuildPBCommit = dependency.Version
case "buf.build/gen/go/chain4travel/camino-messenger-protocol/grpc/go":
BufBuildGRPCCommit = dependency.Version
case "github.com/chain4travel/camino-messenger-contracts/go/contracts":
ContractsGitCommit = dependency.Version
}
}
}
4 changes: 2 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ fi
# Load the constants
source "$CAMINOBOT_PATH"/scripts/constants.sh

LDFLAGS="-X github.com/chain4travel/camino-messenger-bot/cmd.GitCommit=$git_commit"
LDFLAGS="$LDFLAGS -X github.com/chain4travel/camino-messenger-bot/cmd.Version=$git_tag"
LDFLAGS="-X github.com/chain4travel/camino-messenger-bot/internal/version.AppGitCommit=$git_commit"
LDFLAGS="$LDFLAGS -X github.com/chain4travel/camino-messenger-bot/internal/version.AppVersion=$git_tag"

# Build the Go application
echo "Building camino-messenger-bot..."
Expand Down

0 comments on commit 77eb70d

Please sign in to comment.