diff --git a/Taskfile.yml b/Taskfile.yml index 2972786a9..a07bcc46e 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 -u +"%Y-%m-%dT%H:%M:%SZ")" 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 cd9c89a65..20e9cc95b 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 1ba5619ce..75c74d3c7 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 062bcc4f1..d538cec0c 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 883e25281..0dab9c654 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()) +}