From cdcacfe7533e106547faa294efa28471b3579e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Tigerstr=C3=B6m?= Date: Thu, 22 May 2025 12:10:30 +0200 Subject: [PATCH 1/3] 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. --- Makefile | 6 ++++-- loopd/swapclient_server.go | 9 ++++++++- looprpc/client.pb.go | 4 +++- looprpc/client.proto | 4 +++- looprpc/client.swagger.json | 2 +- version.go | 26 ++++++++++++++++---------- 6 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 798596d18..566bae87d 100644 --- a/Makefile +++ b/Makefile @@ -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") diff --git a/loopd/swapclient_server.go b/loopd/swapclient_server.go index 651a8107c..cc4a80448 100644 --- a/loopd/swapclient_server.go +++ b/loopd/swapclient_server.go @@ -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, diff --git a/looprpc/client.pb.go b/looprpc/client.pb.go index a4572dcc4..6e19b8e1e 100644 --- a/looprpc/client.pb.go +++ b/looprpc/client.pb.go @@ -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"` } diff --git a/looprpc/client.proto b/looprpc/client.proto index f3858a7bf..234715812 100644 --- a/looprpc/client.proto +++ b/looprpc/client.proto @@ -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; } diff --git a/looprpc/client.swagger.json b/looprpc/client.swagger.json index 291773f33..a86a3ed0f 100644 --- a/looprpc/client.swagger.json +++ b/looprpc/client.swagger.json @@ -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\"." } } }, diff --git a/version.go b/version.go index 6335da712..82832bcc0 100644 --- a/version.go +++ b/version.go @@ -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 { From 78c406d67e90c2a9fdcbc7c760c1a3e28b6b59b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Tigerstr=C3=B6m?= Date: Thu, 22 May 2025 12:20:24 +0200 Subject: [PATCH 2/3] loop: add `commit_hash` to --version output The `commit_hash` field will contain the full commit hash of the commit that build was based on. --- version.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/version.go b/version.go index 82832bcc0..e6fe9c39c 100644 --- a/version.go +++ b/version.go @@ -64,10 +64,14 @@ func Version() string { // RichVersion returns the application version as a properly formed string // per the semantic versioning 2.0.0 spec (http://semver.org/), followed by the -// most recent git tag the build was built on. +// most recent git tag and commit hash the build was built on. func RichVersion() string { - // Append the most recent git tag of the current build to version. - return fmt.Sprintf("%s commit=%s", semanticVersion(), Commit) + // Append the most recent git tag and commit hash of the current build + // to version. + return fmt.Sprintf( + "%s commit=%s commit_hash=%s", semanticVersion(), Commit, + CommitHash, + ) } // UserAgent returns the full user agent string that identifies the software From 3aaef99bec5c387af84443faecab040fef684945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Tigerstr=C3=B6m?= Date: Thu, 22 May 2025 16:34:18 +0200 Subject: [PATCH 3/3] docs: add release notes --- release_notes.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/release_notes.md b/release_notes.md index 38afc603e..bbd376aef 100644 --- a/release_notes.md +++ b/release_notes.md @@ -18,6 +18,11 @@ This file tracks release notes for the loop client. #### Breaking Changes +* The content of the `commit_hash` field of the `GetInfo` response has been updated so that it contains 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". +* The `Commit` part of the `--version` command output has been updated to contain the most recent git commit tag. + #### Bug Fixes #### Maintenance