Skip to content

Commit e40634c

Browse files
committed
chore: add build info logging
This will provide some information about build env and version
1 parent 77a1c2f commit e40634c

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

cmd/zigbee/firmware/root.go

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package firmware
22

3-
import "github.com/urfave/cli/v2"
3+
import (
4+
"errors"
5+
"log"
6+
"runtime/debug"
7+
"slices"
8+
9+
"github.com/urfave/cli/v2"
10+
)
411

512
func RootCmd() *cli.Command {
613
return &cli.Command{
@@ -16,5 +23,37 @@ func RootCmd() *cli.Command {
1623
Usage: "change the working directory for the build process (currently does not do anything)",
1724
},
1825
},
26+
Before: func(ctx *cli.Context) error {
27+
buildInfo, ok := debug.ReadBuildInfo()
28+
if !ok {
29+
return errors.New("could not read build information")
30+
}
31+
32+
vcsProps := make([]debug.BuildSetting, 0, 2)
33+
34+
for _, setting := range buildInfo.Settings {
35+
if !slices.Contains([]string{"vcs.revision", "vcs.modified"}, setting.Key) {
36+
continue
37+
}
38+
39+
vcsProps = append(vcsProps, setting)
40+
if len(vcsProps) == 3 {
41+
break
42+
}
43+
}
44+
45+
slices.SortFunc(vcsProps, func(a, b debug.BuildSetting) int {
46+
if a.Key > b.Key {
47+
return 1
48+
}
49+
50+
return -1
51+
})
52+
53+
// Information that will help with investigation of issues
54+
log.Printf("build info: %s/%s, %s", buildInfo.GoVersion, buildInfo.Main.Version, vcsProps)
55+
56+
return nil
57+
},
1958
}
2059
}

0 commit comments

Comments
 (0)