Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make version more flexible to allow kapp to be used as a library #897

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 34 additions & 1 deletion pkg/kapp/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,37 @@

package version

var Version = "develop"
import "runtime/debug"

var (
// Version can be set via:
// -ldflags="-X 'github.com/vmware-tanzu/carvel-kapp/pkg/kapp/version.Version=$TAG'"
defaultVersion = "develop"
Version = ""
moduleName = "github.com/vmware-tanzu/carvel-kapp"
)

func init() {
Version = version()
}

func version() string {
if Version != "" {
// Version was set via ldflags, just return it.
return Version
}

info, ok := debug.ReadBuildInfo()
if !ok {
return defaultVersion
}

// Anything else.
for _, dep := range info.Deps {
if dep.Path == moduleName {
return dep.Version
}
}

return defaultVersion
}