Skip to content

Update commit_hash field to GetInfo response #946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 8 additions & 1 deletion loopd/swapclient_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion looprpc/client.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion looprpc/client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion looprpc/client.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"."
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 21 additions & 11 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -52,16 +63,15 @@ 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 and commit hash the build 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
// 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
Expand Down