Skip to content

Commit d5307a7

Browse files
committed
Add build timestamp to the --version output
1 parent 385b1e8 commit d5307a7

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

Diff for: Taskfile.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ vars:
184184
# build vars
185185
COMMIT:
186186
sh: echo "$(git log -n 1 --format=%h)"
187+
TIMESTAMP:
188+
sh: echo "$(date --utc --iso-8601=second)"
187189
LDFLAGS: >
188-
-ldflags '-X github.com/arduino/arduino-check/configuration.commit={{.COMMIT}}'
190+
-ldflags '-X github.com/arduino/arduino-check/configuration.commit={{.COMMIT}} -X github.com/arduino/arduino-check/configuration.buildTimestamp={{.TIMESTAMP}}'
189191
GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic"
190192

191193
GOLINTFLAGS: "-min_confidence 0.8 -set_exit_status"

Diff for: cli/cli.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Root() *cobra.Command {
3939
rootCommand.PersistentFlags().String("project-type", "all", "Only check projects of the specified type and their subprojects. Can be {sketch|library|all}.")
4040
rootCommand.PersistentFlags().Bool("recursive", true, "Search path recursively for Arduino projects to check. Can be {true|false}.")
4141
rootCommand.PersistentFlags().String("report-file", "", "Save a report on the checks to this file.")
42-
rootCommand.PersistentFlags().Bool("version", false, "Print version.")
42+
rootCommand.PersistentFlags().Bool("version", false, "Print version and timestamp of the build.")
4343

4444
return rootCommand
4545
}

Diff for: command/command.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ func ArduinoCheck(rootCommand *cobra.Command, cliArguments []string) {
3939

4040
if configuration.VersionMode() {
4141
if configuration.OutputFormat() == outputformat.Text {
42-
fmt.Println(configuration.Version())
42+
fmt.Println(configuration.Version() + " " + configuration.BuildTimestamp())
4343
} else {
4444
versionObject := struct {
45-
Version string `json:"version"`
45+
Version string `json:"version"`
46+
BuildTimestamp string `json:"buildTimestamp"`
4647
}{
47-
Version: configuration.Version(),
48+
Version: configuration.Version(),
49+
BuildTimestamp: configuration.BuildTimestamp(),
4850
}
4951
versionJSON, err := json.MarshalIndent(versionObject, "", " ")
5052
if err != nil {

Diff for: configuration/configuration.go

+6
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ func Version() string {
193193
return version
194194
}
195195

196+
var buildTimestamp string
197+
198+
func BuildTimestamp() string {
199+
return buildTimestamp
200+
}
201+
196202
var targetPaths paths.PathList
197203

198204
// TargetPaths returns the projects search paths.

Diff for: configuration/configuration_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,8 @@ func TestVersion(t *testing.T) {
220220
version = "42.1.2"
221221
assert.Equal(t, version, Version())
222222
}
223+
224+
func TestBuildTimestamp(t *testing.T) {
225+
buildTimestamp = "2020-11-27T04:05:19+00:00"
226+
assert.Equal(t, buildTimestamp, BuildTimestamp())
227+
}

0 commit comments

Comments
 (0)