Skip to content

Commit

Permalink
Fix version tag management
Browse files Browse the repository at this point in the history
  • Loading branch information
chansuke committed Dec 8, 2023
1 parent 557d6cb commit ff4a022
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Makefile
Expand Up @@ -75,7 +75,9 @@ $(MYGOBIN)/pluginator:
# Build from local source.
$(MYGOBIN)/kustomize: build-kustomize-api
cd kustomize; \
go install -ldflags "-X sigs.k8s.io/kustomize/api/provenance.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')" \
go install -ldflags \
"-X sigs.k8s.io/kustomize/api/provenance.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
-X sigs.k8s.io/kustomize/api/provenance.version=$(shell git describe --tags --always --dirty)" \
.

kustomize: $(MYGOBIN)/kustomize
Expand Down
1 change: 1 addition & 0 deletions api/go.mod
Expand Up @@ -15,6 +15,7 @@ require (
)

require (
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions api/go.sum
@@ -1,3 +1,5 @@
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
Expand Down
32 changes: 32 additions & 0 deletions api/provenance/provenance.go
Expand Up @@ -8,6 +8,8 @@ import (
"runtime"
"runtime/debug"
"strings"

"github.com/blang/semver/v4"
)

// These variables are set at build time using ldflags.
Expand Down Expand Up @@ -62,9 +64,39 @@ func GetProvenance() Provenance {
p.GitCommit = setting.Value
}
}

for _, dep := range info.Deps {
if dep != nil {
continue
}
if 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(
Expand Down

0 comments on commit ff4a022

Please sign in to comment.