Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 5 additions & 3 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}