Fix version tag management

This commit is contained in:
chansuke
2023-11-24 00:56:36 +09:00
parent 557d6cba2d
commit cd886102a9
5 changed files with 83 additions and 1 deletions

View File

@@ -8,6 +8,8 @@ import (
"runtime"
"runtime/debug"
"strings"
"github.com/blang/semver/v4"
)
// These variables are set at build time using ldflags.
@@ -62,9 +64,34 @@ func GetProvenance() Provenance {
p.GitCommit = setting.Value
}
}
for _, dep := range info.Deps {
if dep != nil && dep.Path == "sigs.k8s.io/kustomize/kustomize/v5" {
p.Version = GetMostRecentTag(*dep)
}
}
return p
}
func GetMostRecentTag(m debug.Module) string {
for m.Replace != nil {
m = *m.Replace
}
split := strings.Split(m.Version, "-")
sv, err := semver.Parse(strings.TrimPrefix(split[0], "v"))
if err != nil {
return "unknown"
}
if len(split) > 1 && sv.Patch > 0 {
sv.Patch -= 1
}
return fmt.Sprintf("v%s", sv.FinalizeVersion())
}
// Short returns the shortened provenance stamp.
func (v Provenance) Short() string {
return fmt.Sprintf(