Skip to content

Commit

Permalink
feat: return commit date in device infos
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Nov 21, 2018
1 parent 637d3e0 commit 80b1593
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
3 changes: 2 additions & 1 deletion client/react-native/gomobile/Makefile
Expand Up @@ -17,7 +17,8 @@ BLE_BIND_PATH := /tmp/ble
GIT_SHA ?= $(shell git rev-parse HEAD)
GIT_TAG ?= $(shell git describe --tags --always)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
EXT_LDFLAGS ?= -ldflags="-X \"berty.tech/client/react-native/gomobile/vendor/berty.tech/core.GitTag=$(GIT_TAG)\" -X \"berty.tech/client/react-native/gomobile/vendor/berty.tech/core.GitBranch=$(GIT_BRANCH)\" -X \"berty.tech/client/react-native/gomobile/vendor/berty.tech/core.GitSha=$(GIT_SHA)\" -X \"berty.tech/client/react-native/gomobile/vendor/berty.tech/core.BuildMode=$(BUILD_MODE)\""
GIT_COMMIT_DATE ?= $(shell git show -s --format=%ct $(GIT_SHA))
EXT_LDFLAGS ?= -ldflags="-X \"berty.tech/client/react-native/gomobile/vendor/berty.tech/core.GitTag=$(GIT_TAG)\" -X \"berty.tech/client/react-native/gomobile/vendor/berty.tech/core.GitBranch=$(GIT_BRANCH)\" -X \"berty.tech/client/react-native/gomobile/vendor/berty.tech/core.GitSha=$(GIT_SHA)\" -X \"berty.tech/client/react-native/gomobile/vendor/berty.tech/core.BuildMode=$(BUILD_MODE)\" -X \"berty.tech/client/react-native/gomobile/vendor/berty.tech/core.commitDate=$(GIT_COMMIT_DATE)\""

GOPATH ?= $(HOME)/go

Expand Down
3 changes: 2 additions & 1 deletion core/Makefile
Expand Up @@ -22,7 +22,8 @@ BUILD_ENV ?= GO111MODULE=on CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CPPFLAGS="$(CGO_CPP
GIT_SHA ?= $(shell git rev-parse HEAD)
GIT_TAG ?= $(shell git describe --tags --always)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
EXT_LDFLAGS ?= -ldflags "-X berty.tech/core.GitSha=$(GIT_SHA) -X berty.tech/core.GitTag=$(GIT_TAG) -X berty.tech/core.GitBranch=$(GIT_BRANCH) -X berty.tech/core.BuildMode=$(BUILD_MODE)"
GIT_COMMIT_DATE ?= $(shell git show -s --format=%ct $(GIT_SHA))
EXT_LDFLAGS ?= -ldflags "-X berty.tech/core.GitSha=$(GIT_SHA) -X berty.tech/core.GitTag=$(GIT_TAG) -X berty.tech/core.GitBranch=$(GIT_BRANCH) -X berty.tech/core.BuildMode=$(BUILD_MODE) -X berty.tech/core.commitDate=$(GIT_COMMIT_DATE)"
RUN_DAEMON_OPTS ?= --log-level=debug
TEST_PATHS ?= ./...
TEST_OPTS ?= -v
Expand Down
4 changes: 2 additions & 2 deletions core/cmd/berty/root.go
Expand Up @@ -62,8 +62,8 @@ func newRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "berty",
Version: fmt.Sprintf(
"core=%s p2p=%d node=%d git_sha=%s git_branch=%s git_tag=%s build_mode=%s",
core.Version, p2p.Version, node.Version, core.GitSha, core.GitBranch, core.GitTag, core.BuildMode,
"core=%s p2p=%d node=%d git_sha=%s git_branch=%s git_tag=%s build_mode=%s commit_date=%s",
core.Version, p2p.Version, node.Version, core.GitSha, core.GitBranch, core.GitTag, core.BuildMode, core.CommitDate(),
),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := setupLogger(cmd, args); err != nil {
Expand Down
1 change: 1 addition & 0 deletions core/manager/account/account.go
Expand Up @@ -210,6 +210,7 @@ func (a *Account) Open() error {
zap.String("git-sha", core.GitSha),
zap.String("git-branch", core.GitBranch),
zap.String("build-mode", core.BuildMode),
zap.String("commit-date", core.CommitDate()),
zap.String("db", a.dbPath()),
zap.String("name", a.Name),
)
Expand Down
2 changes: 1 addition & 1 deletion core/node/nodeapi_devtools.go
Expand Up @@ -121,7 +121,7 @@ func (n *Node) NodeInfos() (map[string]string, error) {
infos := map[string]string{}

infos["runtime: versions"] = fmt.Sprintf("core=%s\np2p=%d\nnode=%d", core.Version, p2p.Version, node.Version)
infos["build: git"] = fmt.Sprintf("sha=%s\ntag=%s\nbranch=%s\nmode=%s", core.GitSha, core.GitTag, core.GitBranch, core.BuildMode)
infos["build: git"] = fmt.Sprintf("sha=%s\ntag=%s\nbranch=%s\nmode=%s\ncommit-date=%s", core.GitSha, core.GitTag, core.GitBranch, core.BuildMode, core.CommitDate())

infos["time: node uptime"] = fmt.Sprintf("%s", time.Since(n.createdAt))
infos["time: node db creation"] = fmt.Sprintf("%s", time.Since(n.config.CreatedAt))
Expand Down
27 changes: 23 additions & 4 deletions core/version.go
@@ -1,13 +1,32 @@
package core // import "berty.tech/core"

import (
"strconv"
"time"
)

var (
// Version is the core semver version
Version = "1.0.0"

// the following variables are updated at build phase using `go build -X`

GitSha = "undefined"
GitTag = "undefined"
GitBranch = "undefined"
BuildMode = "undefined"
GitSha = "undefined"
GitTag = "undefined"
GitBranch = "undefined"
BuildMode = "undefined"
commitDate = "undefined"
)

func CommitDate() string {
if commitDate == "undefined" {
return "undefined"
}

commitDateInt, err := strconv.ParseInt(commitDate, 10, 64)
if err != nil {
return "parse-error"
}
tm := time.Unix(commitDateInt, 0)
return tm.Format(time.RFC3339)
}

0 comments on commit 80b1593

Please sign in to comment.