Commit 0c04cf56 authored by Peter Mrekaj's avatar Peter Mrekaj Committed by GitHub

fix: set commit time to the current time when missing (#2191)

Sets the commit time to the current time when the
node is running directly from the source code
without compilation.
parent 401e6fc0
...@@ -12,7 +12,7 @@ BEEKEEPER_BRANCH ?= master ...@@ -12,7 +12,7 @@ BEEKEEPER_BRANCH ?= master
COMMIT ?= "$(shell git describe --long --dirty --always --match "" || true)" COMMIT ?= "$(shell git describe --long --dirty --always --match "" || true)"
CLEAN_COMMIT ?= "$(shell git describe --long --always --match "" || true)" CLEAN_COMMIT ?= "$(shell git describe --long --always --match "" || true)"
COMMIT_TIME ?= "$(shell git show -s --format=%ct $(CLEAN_COMMIT) || true)" COMMIT_TIME ?= "$(shell git show -s --format=%ct $(CLEAN_COMMIT) || true)"
LDFLAGS ?= -s -w -X github.com/ethersphere/bee.commit="$(COMMIT)" -X github.com/ethersphere/bee.CommitTime="$(COMMIT_TIME)" LDFLAGS ?= -s -w -X github.com/ethersphere/bee.commit="$(COMMIT)" -X github.com/ethersphere/bee.commitTime="$(COMMIT_TIME)"
.PHONY: all .PHONY: all
all: build lint vet test-race binary all: build lint vet test-race binary
......
...@@ -15,7 +15,7 @@ const ( ...@@ -15,7 +15,7 @@ const (
) )
var ( var (
commitTime, _ = strconv.ParseInt(bee.CommitTime, 10, 64) commitTime, _ = strconv.ParseInt(bee.CommitTime(), 10, 64)
versionReleased = time.Unix(commitTime, 0) versionReleased = time.Unix(commitTime, 0)
) )
......
...@@ -4,16 +4,30 @@ ...@@ -4,16 +4,30 @@
package bee package bee
var CommitTime string import (
"strconv"
"time"
)
var ( var (
version = "1.0.1" // manually set semantic version number version = "1.0.1" // manually set semantic version number
commit string // automatically set git commit hash commitHash string // automatically set git commit hash
commitTime string // automatically set git commit time
Version = func() string { Version = func() string {
if commit != "" { if commitHash != "" {
return version + "-" + commit return version + "-" + commitHash
} }
return version + "-dev" return version + "-dev"
}() }()
// CommitTime returns the time of the commit from which this code was derived.
// If it's not set (in the case of running the code directly without compilation)
// then the current time will be returned.
CommitTime = func() string {
if commitTime == "" {
commitTime = strconv.Itoa(int(time.Now().Unix()))
}
return commitTime
}
) )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment