Skip to content

Commit

Permalink
feat(version): add details reported by "qri version"
Browse files Browse the repository at this point in the history
since we ask for the output of "qri version" of bug reports, adding more
info to the version command will really help debugging. Specifically,
getting the git commitish hash to print as part of "qri version".

this requires using "make" to build instead of go install and go build
directly, but is well worth it.

All of this is directly inspired by great work over at
github.com/textileio/powergate
  • Loading branch information
b5 committed Nov 30, 2020
1 parent b683443 commit e6a0a67
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 24 deletions.
28 changes: 11 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

default: build

QRI_VERSION?="0.9.14-dev"

BUILD_FLAGS?=CGO_ENABLED=0
PKG=$(shell go list ./version)
GOLANG_VERSION=$(shell go version | awk '{print $$3}')
GOVVV_FLAGS=$(shell govvv -flags -pkg $(PKG) -version $(QRI_VERSION))

require-goversion:
$(eval minver := go1.13)
# Get the version of the current go binary
Expand All @@ -18,24 +25,11 @@ require-goversion:
fi;

build: require-goversion
go install

build-latest:
git checkout master && git pull
build
$(BUILD_FLAGS) go build -ldflags="-X ${PKG}.GolangVersion=${GOLANG_VERSION} ${GOVVV_FLAGS}" .

update-qri-deps: require-gopath
cd $$GOPATH/src/github.com/qri-io/qri && git checkout master && git pull && gx install
cd $$GOPATH/src/github.com/qri-io/qfs && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/qri/registry && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/dataset && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/varName && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/deepdiff && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/jsonschema && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/starlib && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/dag && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/ioes && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/qri
install: require-goversion
$(BUILD_FLAGS) go install -ldflags="-X ${PKG}.GolangVersion=${GOLANG_VERSION} ${GOVVV_FLAGS}" .
.PHONY: install

dscache_fbs:
cd dscache && flatc --go def.fbs
Expand Down
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
var (
log = golog.Logger("qriapi")
// APIVersion is the version string that is written in API responses
APIVersion = version.String
APIVersion = version.Version
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ For updates & further information check https://github.com/qri-io/qri/releases`,
},
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
printInfo(ioStreams.Out, version.String)
printInfo(ioStreams.Out, version.Summary())
return nil
},
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/qri-io/qri
go 1.13

require (
github.com/ahmetb/govvv v0.3.0 // indirect
github.com/axiomhq/hyperloglog v0.0.0-20191112132149-a4c4c47bc57f
github.com/beme/abide v0.0.0-20190723115211-635a09831760
github.com/cheggaaa/pb/v3 v3.0.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ github.com/Stebalien/go-bitfield v0.0.1/go.mod h1:GNjFpasyUVkHMsfEOk8EFLJ9syQ6SI
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/ahmetb/govvv v0.3.0 h1:YGLGwEyiUwHFy5eh/RUhdupbuaCGBYn5T5GWXp+WJB0=
github.com/ahmetb/govvv v0.3.0/go.mod h1:4WRFpdWtc/YtKgPFwa1dr5+9hiRY5uKAL08bOlxOR6s=
github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75/go.mod h1:uAXEEpARkRhCZfEvy/y0Jcc888f9tHCc1W7/UeEtreE=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down
2 changes: 1 addition & 1 deletion p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var (
log = golog.Logger("qrip2p")
// QriServiceTag marks the type & version of the qri service
QriServiceTag = fmt.Sprintf("qri/%s", version.String)
QriServiceTag = fmt.Sprintf("qri/%s", version.Version)
// ErrNotConnected is for a missing required network connection
ErrNotConnected = fmt.Errorf("no p2p connection")
// ErrQriProtocolNotSupported is returned when a connection can't be upgraded
Expand Down
2 changes: 1 addition & 1 deletion remote/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ func (c *client) signHTTPRequest(req *http.Request) error {
req.Header.Add("timestamp", now)
req.Header.Add("pid", peerID)
req.Header.Add("signature", b64Sig)
req.Header.Add("qri-version", version.String)
req.Header.Add("qri-version", version.Version)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion startf/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

// Version is the version of qri that this transform was run with
var Version = version.String
var Version = version.Version

// ExecOpts defines options for execution
type ExecOpts struct {
Expand Down
34 changes: 32 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
package version

// String is the version number of qri
const String = "0.9.14-dev"
import "fmt"

var (
// Version is set by govvv at build time
Version = "n/a"
// GitCommit is set by govvv at build time
GitCommit = "n/a"
// GitBranch is set by govvv at build time
GitBranch = "n/a"
// GitState is set by govvv at build time
GitState = "n/a"
// GitSummary is set by govvv at build time
GitSummary = "n/a"
// BuildDate is set by govvv at build time
BuildDate = "n/a"
// GolangVersion is set by govvv at build time
GolangVersion = "n/a"
)

// Summary prints a summary of all build info.
func Summary() string {
return fmt.Sprintf(
"version:\t%s\n\nbuild date:\t%s\ngit summary:\t%s\ngit branch:\t%s\ngit commit:\t%s\ngit state:\t%s\ngolang version:\t%s",
Version,
BuildDate,
GitSummary,
GitBranch,
GitCommit,
GitState,
GolangVersion,
)
}

0 comments on commit e6a0a67

Please sign in to comment.