Skip to content

Commit

Permalink
Revert "[chore] delete code to set a version and date, as it it not u…
Browse files Browse the repository at this point in the history
…sed (open-telemetry#10715)"

This reverts commit b53f57d.
  • Loading branch information
jackgopack4 committed Sep 18, 2024
1 parent 59c083f commit 5c5a632
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/builder/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ configuration is provided, ocb will generate a default Collector.

func initConfig(flags *flag.FlagSet) error {
cfg.Logger.Info("OpenTelemetry Collector Builder",
zap.String("version", version))
zap.String("version", version), zap.String("date", date))

var provider koanf.Provider

Expand Down
21 changes: 17 additions & 4 deletions cmd/builder/internal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ import (

var (
version = ""
date = "unknown"
)

func init() {
// the second returned value is a boolean, which is true if the binaries are built with module support.
info, _ := debug.ReadBuildInfo()
version = info.Main.Version
// binVersion returns the version of the binary.
// If the version is not set, it attempts to read the build information.
// Returns an error if the build information cannot be read.
func binVersion() (string, error) {
if version != "" {
return version, nil
}
info, ok := debug.ReadBuildInfo()
if !ok {
return "", fmt.Errorf("failed to read build info")
}
return info.Main.Version, nil
}

func versionCommand() *cobra.Command {
Expand All @@ -26,6 +35,10 @@ func versionCommand() *cobra.Command {
Short: "Version of ocb",
Long: "Prints the version of the ocb binary",
RunE: func(cmd *cobra.Command, _ []string) error {
version, err := binVersion()
if err != nil {
return err
}
cmd.Println(fmt.Sprintf("%s version %s", cmd.Parent().Name(), version))
return nil
},
Expand Down

0 comments on commit 5c5a632

Please sign in to comment.