Skip to content

Commit e6a0a67

Browse files
committed
feat(version): add details reported by "qri version"
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
1 parent b683443 commit e6a0a67

File tree

9 files changed

+51
-24
lines changed

9 files changed

+51
-24
lines changed

Makefile

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11

22
default: build
33

4+
QRI_VERSION?="0.9.14-dev"
5+
6+
BUILD_FLAGS?=CGO_ENABLED=0
7+
PKG=$(shell go list ./version)
8+
GOLANG_VERSION=$(shell go version | awk '{print $$3}')
9+
GOVVV_FLAGS=$(shell govvv -flags -pkg $(PKG) -version $(QRI_VERSION))
10+
411
require-goversion:
512
$(eval minver := go1.13)
613
# Get the version of the current go binary
@@ -18,24 +25,11 @@ require-goversion:
1825
fi;
1926

2027
build: require-goversion
21-
go install
22-
23-
build-latest:
24-
git checkout master && git pull
25-
build
28+
$(BUILD_FLAGS) go build -ldflags="-X ${PKG}.GolangVersion=${GOLANG_VERSION} ${GOVVV_FLAGS}" .
2629

27-
update-qri-deps: require-gopath
28-
cd $$GOPATH/src/github.com/qri-io/qri && git checkout master && git pull && gx install
29-
cd $$GOPATH/src/github.com/qri-io/qfs && git checkout master && git pull
30-
cd $$GOPATH/src/github.com/qri-io/qri/registry && git checkout master && git pull
31-
cd $$GOPATH/src/github.com/qri-io/dataset && git checkout master && git pull
32-
cd $$GOPATH/src/github.com/qri-io/varName && git checkout master && git pull
33-
cd $$GOPATH/src/github.com/qri-io/deepdiff && git checkout master && git pull
34-
cd $$GOPATH/src/github.com/qri-io/jsonschema && git checkout master && git pull
35-
cd $$GOPATH/src/github.com/qri-io/starlib && git checkout master && git pull
36-
cd $$GOPATH/src/github.com/qri-io/dag && git checkout master && git pull
37-
cd $$GOPATH/src/github.com/qri-io/ioes && git checkout master && git pull
38-
cd $$GOPATH/src/github.com/qri-io/qri
30+
install: require-goversion
31+
$(BUILD_FLAGS) go install -ldflags="-X ${PKG}.GolangVersion=${GOLANG_VERSION} ${GOVVV_FLAGS}" .
32+
.PHONY: install
3933

4034
dscache_fbs:
4135
cd dscache && flatc --go def.fbs

api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
var (
1818
log = golog.Logger("qriapi")
1919
// APIVersion is the version string that is written in API responses
20-
APIVersion = version.String
20+
APIVersion = version.Version
2121
)
2222

2323
const (

cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ For updates & further information check https://github.com/qri-io/qri/releases`,
1919
},
2020
Args: cobra.NoArgs,
2121
RunE: func(cmd *cobra.Command, args []string) error {
22-
printInfo(ioStreams.Out, version.String)
22+
printInfo(ioStreams.Out, version.Summary())
2323
return nil
2424
},
2525
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/qri-io/qri
33
go 1.13
44

55
require (
6+
github.com/ahmetb/govvv v0.3.0 // indirect
67
github.com/axiomhq/hyperloglog v0.0.0-20191112132149-a4c4c47bc57f
78
github.com/beme/abide v0.0.0-20190723115211-635a09831760
89
github.com/cheggaaa/pb/v3 v3.0.4

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ github.com/Stebalien/go-bitfield v0.0.1/go.mod h1:GNjFpasyUVkHMsfEOk8EFLJ9syQ6SI
4444
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
4545
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
4646
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
47+
github.com/ahmetb/govvv v0.3.0 h1:YGLGwEyiUwHFy5eh/RUhdupbuaCGBYn5T5GWXp+WJB0=
48+
github.com/ahmetb/govvv v0.3.0/go.mod h1:4WRFpdWtc/YtKgPFwa1dr5+9hiRY5uKAL08bOlxOR6s=
4749
github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75/go.mod h1:uAXEEpARkRhCZfEvy/y0Jcc888f9tHCc1W7/UeEtreE=
4850
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
4951
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=

p2p/p2p.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
var (
1414
log = golog.Logger("qrip2p")
1515
// QriServiceTag marks the type & version of the qri service
16-
QriServiceTag = fmt.Sprintf("qri/%s", version.String)
16+
QriServiceTag = fmt.Sprintf("qri/%s", version.Version)
1717
// ErrNotConnected is for a missing required network connection
1818
ErrNotConnected = fmt.Errorf("no p2p connection")
1919
// ErrQriProtocolNotSupported is returned when a connection can't be upgraded

remote/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ func (c *client) signHTTPRequest(req *http.Request) error {
741741
req.Header.Add("timestamp", now)
742742
req.Header.Add("pid", peerID)
743743
req.Header.Add("signature", b64Sig)
744-
req.Header.Add("qri-version", version.String)
744+
req.Header.Add("qri-version", version.Version)
745745
return nil
746746
}
747747

startf/transform.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
// Version is the version of qri that this transform was run with
26-
var Version = version.String
26+
var Version = version.Version
2727

2828
// ExecOpts defines options for execution
2929
type ExecOpts struct {

version/version.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
11
package version
22

3-
// String is the version number of qri
4-
const String = "0.9.14-dev"
3+
import "fmt"
4+
5+
var (
6+
// Version is set by govvv at build time
7+
Version = "n/a"
8+
// GitCommit is set by govvv at build time
9+
GitCommit = "n/a"
10+
// GitBranch is set by govvv at build time
11+
GitBranch = "n/a"
12+
// GitState is set by govvv at build time
13+
GitState = "n/a"
14+
// GitSummary is set by govvv at build time
15+
GitSummary = "n/a"
16+
// BuildDate is set by govvv at build time
17+
BuildDate = "n/a"
18+
// GolangVersion is set by govvv at build time
19+
GolangVersion = "n/a"
20+
)
21+
22+
// Summary prints a summary of all build info.
23+
func Summary() string {
24+
return fmt.Sprintf(
25+
"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",
26+
Version,
27+
BuildDate,
28+
GitSummary,
29+
GitBranch,
30+
GitCommit,
31+
GitState,
32+
GolangVersion,
33+
)
34+
}

0 commit comments

Comments
 (0)