Skip to content

Commit

Permalink
feat(version): Include sonobuoy version in output. Add version sub cmd.
Browse files Browse the repository at this point in the history
  • Loading branch information
bostrt committed Jun 30, 2022
1 parent c740eea commit a3cc5df
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export GO111MODULE=on
# Disable CGO so that we always generate static binaries:
export CGO_ENABLED=0

VERSION=$(shell git rev-parse HEAD)
RELEASE_TAG ?= "0.0.0"
VERSION=$(shell git rev-parse --short HEAD)
RELEASE_TAG ?= 0.0.0

GO_BUILD_FLAGS := -ldflags '-X github.com/openshift/provider-certification-tool/version.commit=$(VERSION) -X github.com/openshift/provider-certification-tool/version.version=$(RELEASE_TAG)'

Expand Down
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ var (

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "openshift-provider-cert",
Short: "OpenShift Provider Certification Tool",
Long: `OpenShift Provider Certification Tool is used to evaluate an OpenShift installation on a provider or hardware is in conformance`,
Version: version.Version.String(),
Use: "openshift-provider-cert",
Short: "OpenShift Provider Certification Tool",
Long: `OpenShift Provider Certification Tool is used to evaluate an OpenShift installation on a provider or hardware is in conformance`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
var err error

Expand Down Expand Up @@ -72,6 +71,7 @@ func init() {
rootCmd.AddCommand(retrieve.NewCmdRetrieve(config))
rootCmd.AddCommand(run.NewCmdRun(config))
rootCmd.AddCommand(status.NewCmdStatus(config))
rootCmd.AddCommand(version.NewCmdVersion())

rootCmd.AddCommand(app.NewSonobuoyCommand())
}
Expand Down
19 changes: 17 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// describing the preflight project.
package version

import "fmt"
import (
"fmt"

"github.com/spf13/cobra"
"github.com/vmware-tanzu/sonobuoy/pkg/buildinfo"
)

var (
projectName = "openshift-provider-cert"
Expand All @@ -23,5 +28,15 @@ type VersionContext struct {
}

func (vc *VersionContext) String() string {
return fmt.Sprintf("%s <commit: %s>", vc.Version, vc.Commit)
return fmt.Sprintf("OpenShift Provider Certification Tool: v%s+%s", vc.Version, vc.Commit)
}
func NewCmdVersion() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Print provider certification tool version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(Version.String())
fmt.Printf("Sonobuoy Version: %s\n", buildinfo.Version)
},
}
}

0 comments on commit a3cc5df

Please sign in to comment.