Skip to content

Commit

Permalink
Merge pull request #466 from carvel-dev/fix-465
Browse files Browse the repository at this point in the history
Make version more flexible to allow kbld to be used as a library
  • Loading branch information
joaopapereira authored Mar 11, 2024
2 parents 771e4b2 + b10a2a8 commit 143d21c
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion pkg/kbld/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,39 @@

package version

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

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

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 143d21c

Please sign in to comment.