multi: update GetInfoResponse response

Update the output of the `commit_hash` field in the GetInfoResponse.
The `commit_hash` field will contain the most recent commit_hash that
the build was based on. If the build had uncommitted changes, this field
will contain the most recent commit hash, suffixed by "-dirty".

Note that this change also changes the output of `commit` field in the
`--version` command. The `Commit` field will now contain most recent git
commit tag.
This commit is contained in:
Viktor Tigerström 2025-05-22 12:10:30 +02:00
parent 48a5f460b9
commit cdcacfe753
No known key found for this signature in database
GPG key ID: B984570980684DCC
6 changed files with 35 additions and 16 deletions

View file

@ -15,8 +15,10 @@ GOBUILD := GO111MODULE=on go build -v
GOINSTALL := GO111MODULE=on go install -v
GOMOD := GO111MODULE=on go mod
COMMIT := $(shell git describe --abbrev=40 --dirty | sed -E 's/.*-g([0-9a-f]{40})(-dirty)?/\1\2/')
LDFLAGS := -ldflags "-X $(PKG).Commit=$(COMMIT)"
COMMIT := $(shell git describe --abbrev=40 --dirty --tags)
COMMIT_HASH := $(shell git rev-parse HEAD)
DIRTY := $(shell git diff-index --quiet HEAD -- || echo dirty)
LDFLAGS := -ldflags "-X $(PKG).Commit=$(COMMIT) -X $(PKG).CommitHash=$(COMMIT_HASH) -X $(PKG).Dirty=$(DIRTY)"
DEV_TAGS = dev
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -name "*pb.go" -not -name "*pb.gw.go" -not -name "*.pb.json.go")

View file

@ -1249,9 +1249,16 @@ func (s *swapClientServer) GetInfo(ctx context.Context,
}
}
commitHash := loop.CommitHash
if loop.Dirty != "" {
// If the build was dirty, we add a "-dirty" suffix to the
// commit hash.
commitHash += "-" + loop.Dirty
}
return &looprpc.GetInfoResponse{
Version: loop.Version(),
CommitHash: loop.CommitHash(),
CommitHash: commitHash,
Network: s.config.Network,
RpcListen: s.config.RPCListen,
RestListen: s.config.RESTListen,

View file

@ -2737,7 +2737,9 @@ type GetInfoResponse struct {
LoopOutStats *LoopStats `protobuf:"bytes,7,opt,name=loop_out_stats,json=loopOutStats,proto3" json:"loop_out_stats,omitempty"`
// Statistics about loop ins.
LoopInStats *LoopStats `protobuf:"bytes,8,opt,name=loop_in_stats,json=loopInStats,proto3" json:"loop_in_stats,omitempty"`
// The git commit hash of the loopd binary.
// The Git commit hash the Loop binary build was based on. If the build had
// uncommited changes, this field will contain the most recent commit hash,
// suffixed by "-dirty".
CommitHash string `protobuf:"bytes,9,opt,name=commit_hash,json=commitHash,proto3" json:"commit_hash,omitempty"`
}

View file

@ -1056,7 +1056,9 @@ message GetInfoResponse {
LoopStats loop_in_stats = 8;
/*
The git commit hash of the loopd binary.
The Git commit hash the Loop binary build was based on. If the build had
uncommited changes, this field will contain the most recent commit hash,
suffixed by "-dirty".
*/
string commit_hash = 9;
}

View file

@ -986,7 +986,7 @@
},
"commit_hash": {
"type": "string",
"description": "The git commit hash of the loopd binary."
"description": "The Git commit hash the Loop binary build was based on. If the build had\nuncommited changes, this field will contain the most recent commit hash,\nsuffixed by \"-dirty\"."
}
}
},

View file

@ -12,10 +12,21 @@ import (
"strings"
)
// Commit stores the current commit hash of this build, this should be set
// using the -ldflags during compilation.
// Commit stores the current git tag of this build, when the build is based on
// a tagged commit. If the build is based on an untagged commit or is a dirty
// build, the Commit field stores the most recent tag suffixed by the commit
// hash, and/or "-dirty". This should be set using the -ldflags during
// compilation.
var Commit string
// CommitHash stores the current git commit hash of this build. This should be
// set using the -ldflags during compilation.
var CommitHash string
// Dirty stores a "dirty" string, if the build had uncommitted changes when
// being built. This should be set using the -ldflags during compilation.
var Dirty string
// semanticAlphabet is the allowed characters from the semantic versioning
// guidelines for pre-release version and build metadata strings. In particular
// they MUST only contain characters in semanticAlphabet.
@ -52,18 +63,13 @@ func Version() string {
}
// RichVersion returns the application version as a properly formed string
// per the semantic versioning 2.0.0 spec (http://semver.org/) and the commit
// it was built on.
// per the semantic versioning 2.0.0 spec (http://semver.org/), followed by the
// most recent git tag the build was built on.
func RichVersion() string {
// Append commit hash of current build to version.
// Append the most recent git tag of the current build to version.
return fmt.Sprintf("%s commit=%s", semanticVersion(), Commit)
}
// CommitHash returns the commit hash of the current build.
func CommitHash() string {
return Commit
}
// UserAgent returns the full user agent string that identifies the software
// that is submitting swaps to the loop server.
func UserAgent(initiator string) string {