diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 654fb7c960..6481cff019 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,7 +25,7 @@ jobs: id: get-product-version run: | CONSUL_VERSION=$(build-support/scripts/version.sh -r) - CONSUL_DATE=$(build-support/scripts/build-date.sh -r) + CONSUL_DATE=$(build-support/scripts/build-date.sh) ## TODO: This assumes `make version` outputs 1.1.1+ent-prerel IFS="+" read VERSION _other <<< "$CONSUL_VERSION" IFS="-" read _other PREREL_VERSION <<< "$CONSUL_VERSION" @@ -100,9 +100,11 @@ jobs: - name: Build UI run: | CONSUL_VERSION=${{ needs.get-product-version.outputs.product-version }} + CONSUL_DATE=${{ needs.get-product-version.outputs.product-date }} CONSUL_BINARY_TYPE=${CONSUL_BINARY_TYPE} CONSUL_COPYRIGHT_YEAR=$(git show -s --format=%cd --date=format:%Y HEAD) echo "consul_version is ${CONSUL_VERSION}" + echo "consul_date is ${CONSUL_DATE}" echo "consul binary type is ${CONSUL_BINARY_TYPE}" echo "consul copyright year is ${CONSUL_COPYRIGHT_YEAR}" cd ui && make && cd .. diff --git a/GNUmakefile b/GNUmakefile index 6bc619e5cc..197a3186d8 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -26,7 +26,7 @@ GIT_COMMIT_YEAR?=$(shell git show -s --format=%cd --date=format:%Y HEAD) GIT_DIRTY?=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true) GIT_IMPORT=github.com/hashicorp/consul/version DATE_FORMAT="%Y-%m-%dT%H:%M:%SZ" # it's tricky to do an RFC3339 format in a cross platform way, so we hardcode UTC -GIT_DATE=$(shell git show -s --format=%cd --date=format:"$(DATE_FORMAT)" HEAD) # we're using this for build date because it's stable across platform builds +GIT_DATE=$(shell $(CURDIR)/build-support/scripts/build-date.sh) # we're using this for build date because it's stable across platform builds GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) -X $(GIT_IMPORT).BuildDate=$(GIT_DATE) ifeq ($(FORCE_REBUILD),1) diff --git a/build-support/functions/10-util.sh b/build-support/functions/10-util.sh index e9a6837bab..9f8fe6d71e 100644 --- a/build-support/functions/10-util.sh +++ b/build-support/functions/10-util.sh @@ -299,7 +299,7 @@ function git_date { # it's tricky to do an RFC3339 format in a cross platform way, so we hardcode UTC local date_format="%Y-%m-%dT%H:%M:%SZ" # we're using this for build date because it's stable across platform builds - local date=$(git show -s --format=%cd --date=format:"$date_format" HEAD) + local date="$(git show -s --format=%cd --date=format:"$date_format" HEAD)" || ret=1 ##local head="$(git status -b --porcelain=v2 | awk '{if ($1 == "#" && $2 =="branch.head") { print $3 }}')" || ret=1 diff --git a/command/agent/agent.go b/command/agent/agent.go index 3bef84b0a8..a929575b52 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -202,6 +202,9 @@ func (c *cmd) run(args []string) int { segment = "" } ui.Info(fmt.Sprintf(" Version: '%s'", c.versionHuman)) + if strings.Contains(c.versionHuman, "dev") { + ui.Info(fmt.Sprintf(" Revision: '%s'", c.revision)) + } ui.Info(fmt.Sprintf(" Build Date: %s", c.buildDate)) ui.Info(fmt.Sprintf(" Node ID: '%s'", config.NodeID)) ui.Info(fmt.Sprintf(" Node name: '%s'", config.NodeName)) diff --git a/command/version/formatter.go b/command/version/formatter.go index 1cfcf5dfd6..c5753f1059 100644 --- a/command/version/formatter.go +++ b/command/version/formatter.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "time" ) const ( @@ -43,6 +44,8 @@ func (_ *prettyFormatter) Format(info *VersionInfo) (string, error) { buffer.WriteString(fmt.Sprintf("Revision %s\n", info.Revision)) } + buffer.WriteString(fmt.Sprintf("Build Date %s\n", info.BuildDate.Format(time.RFC3339))) + var supplement string if info.RPC.Default < info.RPC.Max { supplement = fmt.Sprintf(" (agent will automatically use protocol >%d when speaking to compatible agents)", diff --git a/command/version/formatter_test.go b/command/version/formatter_test.go index b9c6090ac7..bbb12e89f0 100644 --- a/command/version/formatter_test.go +++ b/command/version/formatter_test.go @@ -36,6 +36,7 @@ func TestFormat(t *testing.T) { Version: "1.99.3", Prerelease: "beta1", Revision: "5e5dbedd47a5f875b60e241c5555a9caab595246", + BuildDate: "2022-06-01T13:18:45Z", RPC: RPCVersionInfo{ Default: 2, Min: 1, diff --git a/command/version/testdata/json.golden b/command/version/testdata/json.golden index 20c4a80c07..2e8361f30b 100644 --- a/command/version/testdata/json.golden +++ b/command/version/testdata/json.golden @@ -2,6 +2,7 @@ "Version": "1.99.3", "Revision": "5e5dbedd47a5f875b60e241c5555a9caab595246", "Prerelease": "beta1", + "BuildDate": "2022-06-01T13:18:45Z", "RPC": { "Default": 2, "Min": 1, diff --git a/command/version/testdata/pretty.golden b/command/version/testdata/pretty.golden index 36cb2482c2..c9ee739df9 100644 --- a/command/version/testdata/pretty.golden +++ b/command/version/testdata/pretty.golden @@ -1,3 +1,4 @@ Consul v1.99.3-beta1 Revision 5e5dbedd47a5f875b60e241c5555a9caab595246 +Build Date 2022-06-01T13:18:45Z Protocol 2 spoken by default, understands 1 to 3 (agent will automatically use protocol >2 when speaking to compatible agents) diff --git a/command/version/version.go b/command/version/version.go index 423a6f97da..9cda50ed85 100644 --- a/command/version/version.go +++ b/command/version/version.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "strings" + "time" "github.com/hashicorp/consul/agent/consul" "github.com/hashicorp/consul/command/flags" @@ -46,6 +47,7 @@ type VersionInfo struct { Version string Revision string Prerelease string + BuildDate time.Time RPC RPCVersionInfo } @@ -59,11 +61,20 @@ func (c *cmd) Run(args []string) int { c.UI.Error(err.Error()) return 1 } + + // We parse this here because consul version is used in our 'smoke' tests and we want to fail early + buildDate, err := time.Parse(time.RFC3339, version.BuildDate) + if err != nil { + c.UI.Error(err.Error()) + return 1 + } + out, err := formatter.Format(&VersionInfo{ HumanVersion: version.GetHumanVersion(), Version: version.Version, Revision: version.GitCommit, Prerelease: version.VersionPrerelease, + BuildDate: buildDate, RPC: RPCVersionInfo{ Default: consul.DefaultRPCProtocol, Min: int(consul.ProtocolVersionMin),