From 7dfe3b05115f53c9d40772d3bbfbf72b29a8d8c4 Mon Sep 17 00:00:00 2001 From: bakito Date: Sat, 28 Sep 2024 17:30:46 +0200 Subject: [PATCH] add tb.reset task --- .toolbox.mk | 10 +++++++--- pkg/makefile/{Makefile.tpl => .toolbox.mk.tpl} | 10 +++++++--- pkg/makefile/consts.go | 2 +- pkg/makefile/make.go | 2 +- testdata/.toolbox.mk.content.expected | 10 +++++++--- testdata/.toolbox.mk.hybrid.expected | 10 +++++++--- testdata/.toolbox.mk.renovate.expected | 10 +++++++--- testdata/.toolbox.mk.tools.go.expected | 10 +++++++--- 8 files changed, 44 insertions(+), 20 deletions(-) rename pkg/makefile/{Makefile.tpl => .toolbox.mk.tpl} (94%) diff --git a/.toolbox.mk b/.toolbox.mk index e187ee4..15c6fcc 100644 --- a/.toolbox.mk +++ b/.toolbox.mk @@ -54,9 +54,9 @@ tb.semver: $(TB_SEMVER) ## Download semver locally if necessary. $(TB_SEMVER): $(TB_LOCALBIN) test -s $(TB_LOCALBIN)/semver || GOBIN=$(TB_LOCALBIN) go install github.com/bakito/semver@$(TB_SEMVER_VERSION) -## Update Tools -.PHONY: tb.update -tb.update: +## Reset Tools +.PHONY: tb.reset +tb.reset: @rm -f \ $(TB_LOCALBIN)/deepcopy-gen \ $(TB_LOCALBIN)/ginkgo \ @@ -64,6 +64,10 @@ tb.update: $(TB_LOCALBIN)/goreleaser \ $(TB_LOCALBIN)/oapi-codegen \ $(TB_LOCALBIN)/semver + +## Update Tools +.PHONY: tb.update +tb.update: tb.reset toolbox makefile --renovate -f $(TB_LOCALDIR)/Makefile \ k8s.io/code-generator/cmd/deepcopy-gen@github.com/kubernetes/code-generator \ github.com/golangci/golangci-lint/cmd/golangci-lint \ diff --git a/pkg/makefile/Makefile.tpl b/pkg/makefile/.toolbox.mk.tpl similarity index 94% rename from pkg/makefile/Makefile.tpl rename to pkg/makefile/.toolbox.mk.tpl index b51db9d..39d1f82 100644 --- a/pkg/makefile/Makefile.tpl +++ b/pkg/makefile/.toolbox.mk.tpl @@ -32,12 +32,16 @@ $(TB_{{.UpperName}}): $(TB_LOCALBIN) test -s $(TB_LOCALBIN)/{{.Name}} || GOBIN=$(TB_LOCALBIN) go install {{.ToolName}}{{- if .Version }}@$(TB_{{.UpperName}}_VERSION){{- end }} {{- end }} -## Update Tools -.PHONY: tb.update -tb.update: +## Reset Tools +.PHONY: tb.reset +tb.reset: @rm -f{{- range .Tools }} \ $(TB_LOCALBIN)/{{.Name}} {{- end }} + +## Update Tools +.PHONY: tb.update +tb.update: tb.reset toolbox makefile {{ if $.Renovate }}--renovate {{ end }}-f $(TB_LOCALDIR)/Makefile{{- range .Tools }}{{- if not .FromToolsGo }} \ {{.Tool}}{{- end }} {{- end }} diff --git a/pkg/makefile/consts.go b/pkg/makefile/consts.go index d57e1f9..2a92afe 100644 --- a/pkg/makefile/consts.go +++ b/pkg/makefile/consts.go @@ -12,7 +12,7 @@ const ( ) var ( - //go:embed Makefile.tpl + //go:embed .toolbox.mk.tpl tpl string makefileTemplate = fmt.Sprintf("%s\n%s%s", markerStart, tpl, markerEnd) ) diff --git a/pkg/makefile/make.go b/pkg/makefile/make.go index a31c9b8..207dae6 100644 --- a/pkg/makefile/make.go +++ b/pkg/makefile/make.go @@ -46,7 +46,7 @@ func generate(client *resty.Client, makefile string, renovate bool, argTools []s } out := &bytes.Buffer{} - t := template.Must(template.New("Makefile").Parse(makefileTemplate)) + t := template.Must(template.New("toolbox.mk").Parse(makefileTemplate)) if err := t.Execute(out, map[string]interface{}{ "Tools": toolData, "WithVersions": withVersions, diff --git a/testdata/.toolbox.mk.content.expected b/testdata/.toolbox.mk.content.expected index 2bf3be8..b85e679 100644 --- a/testdata/.toolbox.mk.content.expected +++ b/testdata/.toolbox.mk.content.expected @@ -32,13 +32,17 @@ tb.toolbox: $(TB_TOOLBOX) ## Download toolbox locally if necessary. $(TB_TOOLBOX): $(TB_LOCALBIN) test -s $(TB_LOCALBIN)/toolbox || GOBIN=$(TB_LOCALBIN) go install github.com/bakito/toolbox@$(TB_TOOLBOX_VERSION) -## Update Tools -.PHONY: tb.update -tb.update: +## Reset Tools +.PHONY: tb.reset +tb.reset: @rm -f \ $(TB_LOCALBIN)/controller-gen \ $(TB_LOCALBIN)/semver \ $(TB_LOCALBIN)/toolbox + +## Update Tools +.PHONY: tb.update +tb.update: tb.reset toolbox makefile -f $(TB_LOCALDIR)/Makefile \ sigs.k8s.io/controller-tools/cmd/controller-gen@github.com/kubernetes-sigs/controller-tools \ github.com/bakito/semver \ diff --git a/testdata/.toolbox.mk.hybrid.expected b/testdata/.toolbox.mk.hybrid.expected index 1682e2d..d22d5ad 100644 --- a/testdata/.toolbox.mk.hybrid.expected +++ b/testdata/.toolbox.mk.hybrid.expected @@ -31,13 +31,17 @@ tb.toolbox: $(TB_TOOLBOX) ## Download toolbox locally if necessary. $(TB_TOOLBOX): $(TB_LOCALBIN) test -s $(TB_LOCALBIN)/toolbox || GOBIN=$(TB_LOCALBIN) go install github.com/bakito/toolbox@$(TB_TOOLBOX_VERSION) -## Update Tools -.PHONY: tb.update -tb.update: +## Reset Tools +.PHONY: tb.reset +tb.reset: @rm -f \ $(TB_LOCALBIN)/controller-gen \ $(TB_LOCALBIN)/semver \ $(TB_LOCALBIN)/toolbox + +## Update Tools +.PHONY: tb.update +tb.update: tb.reset toolbox makefile -f $(TB_LOCALDIR)/Makefile \ sigs.k8s.io/controller-tools/cmd/controller-gen@github.com/kubernetes-sigs/controller-tools \ github.com/bakito/toolbox diff --git a/testdata/.toolbox.mk.renovate.expected b/testdata/.toolbox.mk.renovate.expected index 7fcd8a7..fbdbf46 100644 --- a/testdata/.toolbox.mk.renovate.expected +++ b/testdata/.toolbox.mk.renovate.expected @@ -35,13 +35,17 @@ tb.toolbox: $(TB_TOOLBOX) ## Download toolbox locally if necessary. $(TB_TOOLBOX): $(TB_LOCALBIN) test -s $(TB_LOCALBIN)/toolbox || GOBIN=$(TB_LOCALBIN) go install github.com/bakito/toolbox@$(TB_TOOLBOX_VERSION) -## Update Tools -.PHONY: tb.update -tb.update: +## Reset Tools +.PHONY: tb.reset +tb.reset: @rm -f \ $(TB_LOCALBIN)/controller-gen \ $(TB_LOCALBIN)/semver \ $(TB_LOCALBIN)/toolbox + +## Update Tools +.PHONY: tb.update +tb.update: tb.reset toolbox makefile --renovate -f $(TB_LOCALDIR)/Makefile \ sigs.k8s.io/controller-tools/cmd/controller-gen@github.com/kubernetes-sigs/controller-tools \ github.com/bakito/semver \ diff --git a/testdata/.toolbox.mk.tools.go.expected b/testdata/.toolbox.mk.tools.go.expected index aa0512d..cba2558 100644 --- a/testdata/.toolbox.mk.tools.go.expected +++ b/testdata/.toolbox.mk.tools.go.expected @@ -27,12 +27,16 @@ tb.toolbox: $(TB_TOOLBOX) ## Download toolbox locally if necessary. $(TB_TOOLBOX): $(TB_LOCALBIN) test -s $(TB_LOCALBIN)/toolbox || GOBIN=$(TB_LOCALBIN) go install github.com/bakito/toolbox -## Update Tools -.PHONY: tb.update -tb.update: +## Reset Tools +.PHONY: tb.reset +tb.reset: @rm -f \ $(TB_LOCALBIN)/controller-gen \ $(TB_LOCALBIN)/semver \ $(TB_LOCALBIN)/toolbox + +## Update Tools +.PHONY: tb.update +tb.update: tb.reset toolbox makefile -f $(TB_LOCALDIR)/Makefile ## toolbox - end