Skip to content

Commit cdcacfe

Browse files
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.
1 parent 48a5f46 commit cdcacfe

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ GOBUILD := GO111MODULE=on go build -v
1515
GOINSTALL := GO111MODULE=on go install -v
1616
GOMOD := GO111MODULE=on go mod
1717

18-
COMMIT := $(shell git describe --abbrev=40 --dirty | sed -E 's/.*-g([0-9a-f]{40})(-dirty)?/\1\2/')
19-
LDFLAGS := -ldflags "-X $(PKG).Commit=$(COMMIT)"
18+
COMMIT := $(shell git describe --abbrev=40 --dirty --tags)
19+
COMMIT_HASH := $(shell git rev-parse HEAD)
20+
DIRTY := $(shell git diff-index --quiet HEAD -- || echo dirty)
21+
LDFLAGS := -ldflags "-X $(PKG).Commit=$(COMMIT) -X $(PKG).CommitHash=$(COMMIT_HASH) -X $(PKG).Dirty=$(DIRTY)"
2022
DEV_TAGS = dev
2123

2224
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")

loopd/swapclient_server.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,9 +1249,16 @@ func (s *swapClientServer) GetInfo(ctx context.Context,
12491249
}
12501250
}
12511251

1252+
commitHash := loop.CommitHash
1253+
if loop.Dirty != "" {
1254+
// If the build was dirty, we add a "-dirty" suffix to the
1255+
// commit hash.
1256+
commitHash += "-" + loop.Dirty
1257+
}
1258+
12521259
return &looprpc.GetInfoResponse{
12531260
Version: loop.Version(),
1254-
CommitHash: loop.CommitHash(),
1261+
CommitHash: commitHash,
12551262
Network: s.config.Network,
12561263
RpcListen: s.config.RPCListen,
12571264
RestListen: s.config.RESTListen,

looprpc/client.pb.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

looprpc/client.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,9 @@ message GetInfoResponse {
10561056
LoopStats loop_in_stats = 8;
10571057

10581058
/*
1059-
The git commit hash of the loopd binary.
1059+
The Git commit hash the Loop binary build was based on. If the build had
1060+
uncommited changes, this field will contain the most recent commit hash,
1061+
suffixed by "-dirty".
10601062
*/
10611063
string commit_hash = 9;
10621064
}

looprpc/client.swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@
986986
},
987987
"commit_hash": {
988988
"type": "string",
989-
"description": "The git commit hash of the loopd binary."
989+
"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\"."
990990
}
991991
}
992992
},

version.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ import (
1212
"strings"
1313
)
1414

15-
// Commit stores the current commit hash of this build, this should be set
16-
// using the -ldflags during compilation.
15+
// Commit stores the current git tag of this build, when the build is based on
16+
// a tagged commit. If the build is based on an untagged commit or is a dirty
17+
// build, the Commit field stores the most recent tag suffixed by the commit
18+
// hash, and/or "-dirty". This should be set using the -ldflags during
19+
// compilation.
1720
var Commit string
1821

22+
// CommitHash stores the current git commit hash of this build. This should be
23+
// set using the -ldflags during compilation.
24+
var CommitHash string
25+
26+
// Dirty stores a "dirty" string, if the build had uncommitted changes when
27+
// being built. This should be set using the -ldflags during compilation.
28+
var Dirty string
29+
1930
// semanticAlphabet is the allowed characters from the semantic versioning
2031
// guidelines for pre-release version and build metadata strings. In particular
2132
// they MUST only contain characters in semanticAlphabet.
@@ -52,18 +63,13 @@ func Version() string {
5263
}
5364

5465
// RichVersion returns the application version as a properly formed string
55-
// per the semantic versioning 2.0.0 spec (http://semver.org/) and the commit
56-
// it was built on.
66+
// per the semantic versioning 2.0.0 spec (http://semver.org/), followed by the
67+
// most recent git tag the build was built on.
5768
func RichVersion() string {
58-
// Append commit hash of current build to version.
69+
// Append the most recent git tag of the current build to version.
5970
return fmt.Sprintf("%s commit=%s", semanticVersion(), Commit)
6071
}
6172

62-
// CommitHash returns the commit hash of the current build.
63-
func CommitHash() string {
64-
return Commit
65-
}
66-
6773
// UserAgent returns the full user agent string that identifies the software
6874
// that is submitting swaps to the loop server.
6975
func UserAgent(initiator string) string {

0 commit comments

Comments
 (0)