Skip to content

Commit

Permalink
fix: version package receiving build flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mtulio committed Jul 12, 2024
1 parent 2f312fe commit bd3e542
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 37 deletions.
11 changes: 8 additions & 3 deletions openshift-tests-plugin/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@

IMG ?= quay.io/opct/openshift-tests-plugin
VERSION = $(shell git rev-parse --short HEAD)
GO_BUILD_FLAGS ?= -ldflags '-s -X github.com/redhat-openshift-ecosystem/provider-certification-plugin/openshift-tests-plugin/pkg/plugin/version.version=$(VERSION)'
VERSION = v0.0.0-devel
COMMIT = $(shell git rev-parse --short HEAD)
GO_BUILD_FLAGS ?= -ldflags "-s \
-X github.com/redhat-openshift-ecosystem/provider-certification-plugins/openshift-tests-plugin/pkg/version.version=$(VERSION) \
-X github.com/redhat-openshift-ecosystem/provider-certification-plugins/openshift-tests-plugin/pkg/version.commit=$(COMMIT) \
"
GOOS ?= linux
GOARCH ?= amd64

Expand All @@ -11,7 +15,8 @@ clean:

.PHONY: build
build:
GOOS=$(GOOS) GOARCH=$(GOARCH) go build $(GO_BUILD_FLAGS) . && strip ./openshift-tests-plugin
GOOS=$(GOOS) GOARCH=$(GOARCH) go build $(GO_BUILD_FLAGS) . \
&& strip ./openshift-tests-plugin

.PHONY: build-image
build-image:
Expand Down
6 changes: 3 additions & 3 deletions openshift-tests-plugin/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/redhat-openshift-ecosystem/provider-certification-plugins/openshift-tests-plugin/pkg/plugin"
v "github.com/redhat-openshift-ecosystem/provider-certification-plugins/openshift-tests-plugin/pkg/plugin/version"
v "github.com/redhat-openshift-ecosystem/provider-certification-plugins/openshift-tests-plugin/pkg/version"
log "github.com/sirupsen/logrus"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -54,10 +54,10 @@ func NewCmdRun() *cobra.Command {
func StartRun(opt *OptionsRun) error {
pluginName, err := opt.GetPluginName()
if err != nil {
return fmt.Errorf("unable to get plugin name: %w", err)
return fmt.Errorf("plugin name not found: %w", err)
}

log.Infof("Starting plugin %s (%s)", pluginName, v.Version.String())
log.Infof("Starting plugin %s (%s)", pluginName, v.GetFullVersion())

pl, err := plugin.NewPlugin(pluginName)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions openshift-tests-plugin/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"fmt"

v "github.com/redhat-openshift-ecosystem/provider-certification-plugins/openshift-tests-plugin/pkg/plugin/version"
v "github.com/redhat-openshift-ecosystem/provider-certification-plugins/openshift-tests-plugin/pkg/version"
"github.com/spf13/cobra"
)

Expand All @@ -12,7 +12,7 @@ func NewCmdVersion() *cobra.Command {
Use: "version",
Short: "Print provider validation tool version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s %s", v.Version.Name, v.Version.String())
fmt.Printf("%s", v.GetFullVersion())
},
}
}
29 changes: 0 additions & 29 deletions openshift-tests-plugin/pkg/plugin/version/version.go

This file was deleted.

33 changes: 33 additions & 0 deletions openshift-tests-plugin/pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Package version contains all identifiable versioning info for
// describing the openshift provider cert project.
package version

import (
"fmt"
)

var (
programName = "openshift-tests-plugin"
version = "unknown"
commit = "unknown"
)

func GetProgramName() string {
return programName
}

func GetVersion() string {
return version
}

func GetCommit() string {
return commit
}

func GetFullVersion() string {
return fmt.Sprintf("%s+%s", version, commit)
}

func GetFullProgramName() string {
return fmt.Sprintf("%s (%s+%s)", programName, version, commit)
}

0 comments on commit bd3e542

Please sign in to comment.