From d5307a79598d491032451a396840a2b5a964a3f6 Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 26 Nov 2020 20:18:43 -0800 Subject: [PATCH 1/2] Add build timestamp to the --version output --- Taskfile.yml | 4 +++- cli/cli.go | 2 +- command/command.go | 8 +++++--- configuration/configuration.go | 6 ++++++ configuration/configuration_test.go | 5 +++++ 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 2972786a..74296a48 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -184,8 +184,10 @@ vars: # build vars COMMIT: sh: echo "$(git log -n 1 --format=%h)" + TIMESTAMP: + sh: echo "$(date --utc --iso-8601=second)" LDFLAGS: > - -ldflags '-X github.com/arduino/arduino-check/configuration.commit={{.COMMIT}}' + -ldflags '-X github.com/arduino/arduino-check/configuration.commit={{.COMMIT}} -X github.com/arduino/arduino-check/configuration.buildTimestamp={{.TIMESTAMP}}' GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic" GOLINTFLAGS: "-min_confidence 0.8 -set_exit_status" diff --git a/cli/cli.go b/cli/cli.go index cd9c89a6..20e9cc95 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -39,7 +39,7 @@ func Root() *cobra.Command { rootCommand.PersistentFlags().String("project-type", "all", "Only check projects of the specified type and their subprojects. Can be {sketch|library|all}.") rootCommand.PersistentFlags().Bool("recursive", true, "Search path recursively for Arduino projects to check. Can be {true|false}.") rootCommand.PersistentFlags().String("report-file", "", "Save a report on the checks to this file.") - rootCommand.PersistentFlags().Bool("version", false, "Print version.") + rootCommand.PersistentFlags().Bool("version", false, "Print version and timestamp of the build.") return rootCommand } diff --git a/command/command.go b/command/command.go index 1ba5619c..75c74d3c 100644 --- a/command/command.go +++ b/command/command.go @@ -39,12 +39,14 @@ func ArduinoCheck(rootCommand *cobra.Command, cliArguments []string) { if configuration.VersionMode() { if configuration.OutputFormat() == outputformat.Text { - fmt.Println(configuration.Version()) + fmt.Println(configuration.Version() + " " + configuration.BuildTimestamp()) } else { versionObject := struct { - Version string `json:"version"` + Version string `json:"version"` + BuildTimestamp string `json:"buildTimestamp"` }{ - Version: configuration.Version(), + Version: configuration.Version(), + BuildTimestamp: configuration.BuildTimestamp(), } versionJSON, err := json.MarshalIndent(versionObject, "", " ") if err != nil { diff --git a/configuration/configuration.go b/configuration/configuration.go index 062bcc4f..d538cec0 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -193,6 +193,12 @@ func Version() string { return version } +var buildTimestamp string + +func BuildTimestamp() string { + return buildTimestamp +} + var targetPaths paths.PathList // TargetPaths returns the projects search paths. diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index 883e2528..0dab9c65 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -220,3 +220,8 @@ func TestVersion(t *testing.T) { version = "42.1.2" assert.Equal(t, version, Version()) } + +func TestBuildTimestamp(t *testing.T) { + buildTimestamp = "2020-11-27T04:05:19+00:00" + assert.Equal(t, buildTimestamp, BuildTimestamp()) +} From c2aaa06cffe9f8fc8cf8457ccb883e6894b02d96 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 29 Nov 2020 12:36:25 -0800 Subject: [PATCH 2/2] Use macOS-compliant shell command for generating build timestamp The previous command only worked on Linux. --- Taskfile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Taskfile.yml b/Taskfile.yml index 74296a48..a07bcc46 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -185,7 +185,7 @@ vars: COMMIT: sh: echo "$(git log -n 1 --format=%h)" TIMESTAMP: - sh: echo "$(date --utc --iso-8601=second)" + sh: echo "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" LDFLAGS: > -ldflags '-X github.com/arduino/arduino-check/configuration.commit={{.COMMIT}} -X github.com/arduino/arduino-check/configuration.buildTimestamp={{.TIMESTAMP}}' GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic"