Merge pull request #914 from bhandras/ldflags-extended-commit

build+loop: add the commit hash to `GetInfoResponse` and change version semantics
This commit is contained in:
András Bánki-Horváth 2025-04-04 13:01:16 +02:00 committed by GitHub
commit bfe7991c4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 726 additions and 693 deletions

View file

@ -15,7 +15,7 @@ GOBUILD := GO111MODULE=on go build -v
GOINSTALL := GO111MODULE=on go install -v
GOMOD := GO111MODULE=on go mod
COMMIT := $(shell git describe --abbrev=40 --dirty)
COMMIT := $(shell git describe --abbrev=40 --dirty | sed -E 's/.*-g([0-9a-f]{40})(-dirty)?/\1\2/')
LDFLAGS := -ldflags "-X $(PKG).Commit=$(COMMIT)"
DEV_TAGS = dev

View file

@ -162,7 +162,7 @@ func fatal(err error) {
func main() {
app := cli.NewApp()
app.Version = loop.Version()
app.Version = loop.RichVersion()
app.Name = "loop"
app.Usage = "control plane for your loopd"
app.Flags = []cli.Flag{

View file

@ -176,7 +176,7 @@ func Run(rpcCfg RPCConfig) error {
appName := filepath.Base(os.Args[0])
appName = strings.TrimSuffix(appName, filepath.Ext(appName))
if config.ShowVersion {
fmt.Println(appName, "version", loop.Version())
fmt.Println(appName, "version", loop.RichVersion())
os.Exit(0)
}
@ -222,7 +222,7 @@ func Run(rpcCfg RPCConfig) error {
}
// Print the version before executing either primary directive.
infof("Version: %v", loop.Version())
infof("Version: %v", loop.RichVersion())
lisCfg := NewListenerConfig(&config, rpcCfg)

View file

@ -1210,6 +1210,7 @@ func (s *swapClientServer) GetInfo(ctx context.Context,
return &looprpc.GetInfoResponse{
Version: loop.Version(),
CommitHash: loop.CommitHash(),
Network: s.config.Network,
RpcListen: s.config.RPCListen,
RestListen: s.config.RESTListen,

File diff suppressed because it is too large Load diff

View file

@ -1045,6 +1045,11 @@ message GetInfoResponse {
Statistics about loop ins.
*/
LoopStats loop_in_stats = 8;
/*
The git commit hash of the loopd binary.
*/
string commit_hash = 9;
}
message GetLiquidityParamsRequest {

View file

@ -967,6 +967,10 @@
"loop_in_stats": {
"$ref": "#/definitions/looprpcLoopStats",
"description": "Statistics about loop ins."
},
"commit_hash": {
"type": "string",
"description": "The git commit hash of the loopd binary."
}
}
},

View file

@ -45,13 +45,25 @@ const (
var AgentName = defaultAgentName
// Version 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.
// semantic versioning 2.0.0 spec (http://semver.org/).
func Version() string {
// Append commit hash of current build to version.
return semanticVersion()
}
// 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.
func RichVersion() string {
// Append commit hash of 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 {