Skip to content

Commit

Permalink
Make version more flexible to allow vendir to be used as a library
Browse files Browse the repository at this point in the history
Signed-off-by: Joao Pereira <joaod@vmware.com>
  • Loading branch information
joaopapereira committed Mar 8, 2024
1 parent 498f554 commit 631c34b
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion pkg/vendir/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,39 @@

package version

var Version = "0.0.0+develop"
import (
"runtime/debug"
)

var (
// Version can be set via:
// -ldflags="-X 'carvel.dev/vendir/pkg/vendir/version.Version=$TAG'"
defaultVersion = "0.0.0+develop"
Version = ""
moduleName = "carvel.dev/vendir"
)

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
}

0 comments on commit 631c34b

Please sign in to comment.