Skip to content

Commit

Permalink
chore: add build info logging
Browse files Browse the repository at this point in the history
This will provide some information about build env and version
  • Loading branch information
ffenix113 committed May 1, 2024
1 parent 77a1c2f commit e40634c
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion cmd/zigbee/firmware/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package firmware

import "github.com/urfave/cli/v2"
import (
"errors"
"log"
"runtime/debug"
"slices"

"github.com/urfave/cli/v2"
)

func RootCmd() *cli.Command {
return &cli.Command{
Expand All @@ -16,5 +23,37 @@ func RootCmd() *cli.Command {
Usage: "change the working directory for the build process (currently does not do anything)",
},
},
Before: func(ctx *cli.Context) error {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return errors.New("could not read build information")
}

vcsProps := make([]debug.BuildSetting, 0, 2)

for _, setting := range buildInfo.Settings {
if !slices.Contains([]string{"vcs.revision", "vcs.modified"}, setting.Key) {
continue
}

vcsProps = append(vcsProps, setting)
if len(vcsProps) == 3 {
break
}
}

slices.SortFunc(vcsProps, func(a, b debug.BuildSetting) int {
if a.Key > b.Key {
return 1
}

return -1
})

// Information that will help with investigation of issues
log.Printf("build info: %s/%s, %s", buildInfo.GoVersion, buildInfo.Main.Version, vcsProps)

return nil
},
}
}

0 comments on commit e40634c

Please sign in to comment.