From 1a4d34b22f63dac85bdebab3b0ea544e8b3ce400 Mon Sep 17 00:00:00 2001 From: Marc Brugger Date: Sat, 28 Sep 2024 14:55:05 +0200 Subject: [PATCH] handle toolbox tasks in makefile inclide (#131) * prefix for toolbox * refactor * include file * tests --- .toolbox.mk | 71 ++++++++++++++++++++++ Makefile | 84 ++++---------------------- cmd/makefile.go | 15 +---- pkg/makefile/Makefile.tpl | 28 ++++----- pkg/makefile/consts.go | 5 +- pkg/makefile/make.go | 29 ++++++--- pkg/makefile/make_test.go | 56 +++++++++-------- pkg/makefile/renovate.go | 17 +++--- testdata/.toolbox.mk.content.expected | 44 ++++++++++++++ testdata/.toolbox.mk.hybrid.expected | 42 +++++++++++++ testdata/.toolbox.mk.renovate.expected | 47 ++++++++++++++ testdata/.toolbox.mk.tools.go.expected | 36 +++++++++++ testdata/Makefile.content | 8 +-- testdata/Makefile.content.expected | 51 ++-------------- testdata/Makefile.content.migrate | 4 ++ testdata/Makefile.expected | 44 -------------- testdata/Makefile.hybrid.expected | 42 ------------- testdata/Makefile.renovate.expected | 47 -------------- testdata/Makefile.tools.go.expected | 36 ----------- 19 files changed, 341 insertions(+), 365 deletions(-) create mode 100644 .toolbox.mk create mode 100644 testdata/.toolbox.mk.content.expected create mode 100644 testdata/.toolbox.mk.hybrid.expected create mode 100644 testdata/.toolbox.mk.renovate.expected create mode 100644 testdata/.toolbox.mk.tools.go.expected create mode 100644 testdata/Makefile.content.migrate delete mode 100644 testdata/Makefile.expected delete mode 100644 testdata/Makefile.hybrid.expected delete mode 100644 testdata/Makefile.renovate.expected delete mode 100644 testdata/Makefile.tools.go.expected diff --git a/.toolbox.mk b/.toolbox.mk new file mode 100644 index 0000000..475a64c --- /dev/null +++ b/.toolbox.mk @@ -0,0 +1,71 @@ +## toolbox - start +## Current working directory +TB_LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd) +## Location to install dependencies to +TB_LOCALBIN ?= $(TB_LOCALDIR)/bin +$(TB_LOCALBIN): + mkdir -p $(TB_LOCALBIN) + +## Tool Binaries +TB_DEEPCOPY_GEN ?= $(TB_LOCALBIN)/deepcopy-gen +TB_GINKGO ?= $(TB_LOCALBIN)/ginkgo +TB_GOLANGCI_LINT ?= $(TB_LOCALBIN)/golangci-lint +TB_GORELEASER ?= $(TB_LOCALBIN)/goreleaser +TB_OAPI_CODEGEN ?= $(TB_LOCALBIN)/oapi-codegen +TB_SEMVER ?= $(TB_LOCALBIN)/semver + +## Tool Versions +# renovate: packageName=k8s.io/code-generator/cmd/deepcopy-gen +TB_DEEPCOPY_GEN_VERSION ?= v0.31.1 +# renovate: packageName=github.com/golangci/golangci-lint/cmd/golangci-lint +TB_GOLANGCI_LINT_VERSION ?= v1.61.0 +# renovate: packageName=github.com/goreleaser/goreleaser/v2 +TB_GORELEASER_VERSION ?= v2.3.2 +# renovate: packageName=github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen +TB_OAPI_CODEGEN_VERSION ?= v2.4.1 +# renovate: packageName=github.com/bakito/semver +TB_SEMVER_VERSION ?= v1.1.3 + +## Tool Installer +.PHONY: tb.deepcopy-gen +tb.deepcopy-gen: $(TB_DEEPCOPY_GEN) ## Download deepcopy-gen locally if necessary. +$(TB_DEEPCOPY_GEN): $(TB_LOCALBIN) + test -s $(TB_LOCALBIN)/deepcopy-gen || GOBIN=$(TB_LOCALBIN) go install k8s.io/code-generator/cmd/deepcopy-gen@$(TB_DEEPCOPY_GEN_VERSION) +.PHONY: tb.ginkgo +tb.ginkgo: $(TB_GINKGO) ## Download ginkgo locally if necessary. +$(TB_GINKGO): $(TB_LOCALBIN) + test -s $(TB_LOCALBIN)/ginkgo || GOBIN=$(TB_LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo +.PHONY: tb.golangci-lint +tb.golangci-lint: $(TB_GOLANGCI_LINT) ## Download golangci-lint locally if necessary. +$(TB_GOLANGCI_LINT): $(TB_LOCALBIN) + test -s $(TB_LOCALBIN)/golangci-lint || GOBIN=$(TB_LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(TB_GOLANGCI_LINT_VERSION) +.PHONY: tb.goreleaser +tb.goreleaser: $(TB_GORELEASER) ## Download goreleaser locally if necessary. +$(TB_GORELEASER): $(TB_LOCALBIN) + test -s $(TB_LOCALBIN)/goreleaser || GOBIN=$(TB_LOCALBIN) go install github.com/goreleaser/goreleaser/v2@$(TB_GORELEASER_VERSION) +.PHONY: tb.oapi-codegen +tb.oapi-codegen: $(TB_OAPI_CODEGEN) ## Download oapi-codegen locally if necessary. +$(TB_OAPI_CODEGEN): $(TB_LOCALBIN) + test -s $(TB_LOCALBIN)/oapi-codegen || GOBIN=$(TB_LOCALBIN) go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@$(TB_OAPI_CODEGEN_VERSION) +.PHONY: tb.semver +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: + @rm -f \ + $(TB_LOCALBIN)/deepcopy-gen \ + $(TB_LOCALBIN)/ginkgo \ + $(TB_LOCALBIN)/golangci-lint \ + $(TB_LOCALBIN)/goreleaser \ + $(TB_LOCALBIN)/oapi-codegen \ + $(TB_LOCALBIN)/semver + 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 \ + github.com/goreleaser/goreleaser/v2 \ + github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen \ + github.com/bakito/semver +## toolbox - end \ No newline at end of file diff --git a/Makefile b/Makefile index 6de275c..69d6c33 100644 --- a/Makefile +++ b/Makefile @@ -1,82 +1,22 @@ +# Include toolbox tasks +include ./.toolbox.mk + # Run go golanci-lint -lint: golangci-lint - $(GOLANGCI_LINT) run --fix +lint: tb.golangci-lint + $(TB_GOLANGCI_LINT) run --fix # Run go mod tidy tidy: go mod tidy # Run tests -test: ginkgo tidy lint - $(GINKGO) -r --cover --coverprofile=coverage.out +test: tb.ginkgo tidy lint + $(TB_GINKGO) -r --cover --coverprofile=coverage.out -release: goreleaser semver - @version=$$($(SEMVER)); \ +release: tb.goreleaser tb.semver + @version=$$($(TB_SEMVER)); \ git tag -s $$version -m"Release $$version" - $(GORELEASER) --clean - -test-release: goreleaser - $(GORELEASER) --skip=publish --snapshot --clean - -## toolbox - start -## Current working directory -LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd) -## Location to install dependencies to -LOCALBIN ?= $(LOCALDIR)/bin -$(LOCALBIN): - mkdir -p $(LOCALBIN) - -## Tool Binaries -DEEPCOPY_GEN ?= $(LOCALBIN)/deepcopy-gen -GINKGO ?= $(LOCALBIN)/ginkgo -GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint -GORELEASER ?= $(LOCALBIN)/goreleaser -SEMVER ?= $(LOCALBIN)/semver - -## Tool Versions -# renovate: packageName=k8s.io/code-generator/cmd/deepcopy-gen -DEEPCOPY_GEN_VERSION ?= v0.31.1 -# renovate: packageName=github.com/golangci/golangci-lint/cmd/golangci-lint -GOLANGCI_LINT_VERSION ?= v1.61.0 -# renovate: packageName=github.com/goreleaser/goreleaser/v2 -GORELEASER_VERSION ?= v2.3.2 -# renovate: packageName=github.com/bakito/semver -SEMVER_VERSION ?= v1.1.3 - -## Tool Installer -.PHONY: deepcopy-gen -deepcopy-gen: $(DEEPCOPY_GEN) ## Download deepcopy-gen locally if necessary. -$(DEEPCOPY_GEN): $(LOCALBIN) - test -s $(LOCALBIN)/deepcopy-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/deepcopy-gen@$(DEEPCOPY_GEN_VERSION) -.PHONY: ginkgo -ginkgo: $(GINKGO) ## Download ginkgo locally if necessary. -$(GINKGO): $(LOCALBIN) - test -s $(LOCALBIN)/ginkgo || GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo -.PHONY: golangci-lint -golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. -$(GOLANGCI_LINT): $(LOCALBIN) - test -s $(LOCALBIN)/golangci-lint || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) -.PHONY: goreleaser -goreleaser: $(GORELEASER) ## Download goreleaser locally if necessary. -$(GORELEASER): $(LOCALBIN) - test -s $(LOCALBIN)/goreleaser || GOBIN=$(LOCALBIN) go install github.com/goreleaser/goreleaser/v2@$(GORELEASER_VERSION) -.PHONY: semver -semver: $(SEMVER) ## Download semver locally if necessary. -$(SEMVER): $(LOCALBIN) - test -s $(LOCALBIN)/semver || GOBIN=$(LOCALBIN) go install github.com/bakito/semver@$(SEMVER_VERSION) + $(TB_GORELEASER) --clean -## Update Tools -.PHONY: update-toolbox-tools -update-toolbox-tools: - @rm -f \ - $(LOCALBIN)/deepcopy-gen \ - $(LOCALBIN)/ginkgo \ - $(LOCALBIN)/golangci-lint \ - $(LOCALBIN)/goreleaser \ - $(LOCALBIN)/semver - toolbox makefile --renovate -f $(LOCALDIR)/Makefile \ - k8s.io/code-generator/cmd/deepcopy-gen@github.com/kubernetes/code-generator \ - github.com/golangci/golangci-lint/cmd/golangci-lint \ - github.com/goreleaser/goreleaser/v2 \ - github.com/bakito/semver -## toolbox - end +test-release: tb.goreleaser + $(TB_GORELEASER) --skip=publish --snapshot --clean diff --git a/cmd/makefile.go b/cmd/makefile.go index e6d0b2f..a15915b 100644 --- a/cmd/makefile.go +++ b/cmd/makefile.go @@ -1,9 +1,6 @@ package cmd import ( - "errors" - "os" - "github.com/bakito/toolbox/pkg/makefile" "github.com/go-resty/resty/v2" "github.com/spf13/cobra" @@ -21,21 +18,13 @@ var ( makefileCmd = &cobra.Command{ Use: "makefile [tools]", Short: "Adds tools to a Makefile", - Args: func(_ *cobra.Command, args []string) error { - if _, err := os.Stat(toolsGo); err != nil { - if len(args) == 0 { - return errors.New("at least one tool must be provided") - } - } - return nil - }, RunE: func(cmd *cobra.Command, args []string) error { client := resty.New() mf, err := cmd.Flags().GetString(flagFile) if err != nil { return err } - return makefile.Generate(client, cmd.OutOrStderr(), mf, renovate, toolsGo, args...) + return makefile.Generate(client, mf, renovate, toolsGo, args...) }, } ) @@ -43,7 +32,7 @@ var ( func init() { rootCmd.AddCommand(makefileCmd) - makefileCmd.Flags().StringP(flagFile, "f", "", "The Makefile path to generate tools in") + makefileCmd.Flags().StringP(flagFile, "f", "Makefile", "The Makefile path to generate tools in") makefileCmd.Flags().StringVar(&toolsGo, flagToolsGo, "tools.go", "The tools.go file to check for tools dependencies") makefileCmd.Flags().BoolVar(&renovate, "renovate", false, "If enables, renovate config is added to the Makefile (renovate.json file, if existing)") } diff --git a/pkg/makefile/Makefile.tpl b/pkg/makefile/Makefile.tpl index 4142276..443989a 100644 --- a/pkg/makefile/Makefile.tpl +++ b/pkg/makefile/Makefile.tpl @@ -1,13 +1,13 @@ ## Current working directory -LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd) +TB_LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd) ## Location to install dependencies to -LOCALBIN ?= $(LOCALDIR)/bin -$(LOCALBIN): - mkdir -p $(LOCALBIN) +TB_LOCALBIN ?= $(TB_LOCALDIR)/bin +$(TB_LOCALBIN): + mkdir -p $(TB_LOCALBIN) ## Tool Binaries {{- range .Tools }} -{{.UpperName}} ?= $(LOCALBIN)/{{.Name}} +TB_{{.UpperName}} ?= $(TB_LOCALBIN)/{{.Name}} {{- end }} {{- if .WithVersions }} @@ -17,25 +17,25 @@ $(LOCALBIN): {{- if $.Renovate }} # renovate: packageName={{.ToolName}} {{- end }} -{{.UpperName}}_VERSION ?= {{.Version}} +TB_{{.UpperName}}_VERSION ?= {{.Version}} {{- end }} {{- end }} {{- end }} ## Tool Installer {{- range .Tools }} -.PHONY: {{.Name}} -{{.Name}}: $({{.UpperName}}) ## Download {{.Name}} locally if necessary. -$({{.UpperName}}): $(LOCALBIN) - test -s $(LOCALBIN)/{{.Name}} || GOBIN=$(LOCALBIN) go install {{.ToolName}}{{- if .Version }}@$({{.UpperName}}_VERSION){{- end }} +.PHONY: tb.{{.Name}} +tb.{{.Name}}: $(TB_{{.UpperName}}) ## Download {{.Name}} locally if necessary. +$(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: update-toolbox-tools -update-toolbox-tools: +.PHONY: tb.update +tb.update: @rm -f{{- range .Tools }} \ - $(LOCALBIN)/{{.Name}} + $(TB_LOCALBIN)/{{.Name}} {{- end }} - toolbox makefile {{ if $.Renovate }}--renovate {{ end }}-f $(LOCALDIR)/Makefile{{- range .Tools }}{{- if not .FromToolsGo }} \ + 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 4ef48f3..d57e1f9 100644 --- a/pkg/makefile/consts.go +++ b/pkg/makefile/consts.go @@ -6,8 +6,9 @@ import ( ) const ( - markerStart = "## toolbox - start" - markerEnd = "## toolbox - end" + markerStart = "## toolbox - start" + markerEnd = "## toolbox - end" + includeFileName = ".toolbox.mk" ) var ( diff --git a/pkg/makefile/make.go b/pkg/makefile/make.go index dbafd23..a31c9b8 100644 --- a/pkg/makefile/make.go +++ b/pkg/makefile/make.go @@ -3,8 +3,8 @@ package makefile import ( "bytes" "fmt" - "io" "os" + "path/filepath" "regexp" "slices" "sort" @@ -20,12 +20,12 @@ var ( getRelease = github.LatestRelease ) -func Generate(client *resty.Client, writer io.Writer, makefile string, renovate bool, toolsFile string, tools ...string) error { +func Generate(client *resty.Client, makefile string, renovate bool, toolsFile string, tools ...string) error { argTools, toolData := mergeWithToolsGo(toolsFile, unique(tools)) - return generate(client, writer, makefile, renovate, argTools, toolData) + return generate(client, makefile, renovate, argTools, toolData) } -func generate(client *resty.Client, writer io.Writer, makefile string, renovate bool, argTools []string, toolData []toolData) error { +func generate(client *resty.Client, makefile string, renovate bool, argTools []string, toolData []toolData) error { for _, t := range argTools { td, err := dataForArg(client, t) if err != nil { @@ -55,11 +55,13 @@ func generate(client *resty.Client, writer io.Writer, makefile string, renovate return err } - if makefile == "" { - _, err := writer.Write(out.Bytes()) + makefile, err := filepath.Abs(makefile) + if err != nil { return err } + includeFile := filepath.Join(filepath.Dir(makefile), includeFileName) + data, err := os.ReadFile(makefile) if err != nil { return err @@ -75,15 +77,24 @@ func generate(client *resty.Client, writer io.Writer, makefile string, renovate end = parts[1] } } - file := start - file += out.String() - file += end + + var file string + if !strings.Contains(string(data), fmt.Sprintf("include ./%s", includeFileName)) { + file = fmt.Sprintf("# Include toolbox tasks\ninclude ./%s\n\n", includeFileName) + } + + file += start + file += strings.TrimSpace(end) if renovate { if err := updateRenovateConf(); err != nil { return err } } + if err := os.WriteFile(includeFile, out.Bytes(), 0o600); err != nil { + return err + } + return os.WriteFile(makefile, []byte(file), 0o600) } diff --git a/pkg/makefile/make_test.go b/pkg/makefile/make_test.go index 3823a0f..60763b8 100644 --- a/pkg/makefile/make_test.go +++ b/pkg/makefile/make_test.go @@ -1,7 +1,6 @@ package makefile import ( - "bytes" "os" "path/filepath" @@ -15,7 +14,11 @@ import ( const testDataDir = "../../testdata" var _ = Describe("Make", func() { - var tempDir string + var ( + tempDir string + makeFilePath string + includeFilePath string + ) BeforeEach(func() { var err error tempDir, err = os.MkdirTemp("", "toolbox_make_test_") @@ -23,6 +26,8 @@ var _ = Describe("Make", func() { getRelease = func(client *resty.Client, repo string, quiet bool) (*types.GithubRelease, error) { return &types.GithubRelease{TagName: "v0.2.1"}, nil } + makeFilePath = copyFile("Makefile.content", tempDir) + includeFilePath = filepath.Join(tempDir, includeFileName) }) AfterEach(func() { _ = os.RemoveAll(tempDir) @@ -30,78 +35,79 @@ var _ = Describe("Make", func() { }) Context("Generate", func() { It("should generate a correct output", func() { - out := &bytes.Buffer{} - err := Generate(resty.New(), out, "", false, "", + err := Generate(resty.New(), makeFilePath, false, "", "sigs.k8s.io/controller-tools/cmd/controller-gen@github.com/kubernetes-sigs/controller-tools", "github.com/bakito/semver", "github.com/bakito/toolbox", ) Ω(err).ShouldNot(HaveOccurred()) - Ω(out.String() + "\n").Should(Equal(readFile(testDataDir, "Makefile.expected"))) + + Ω(readFile(makeFilePath)).Should(Equal(readFile(testDataDir, "Makefile.content.expected"))) + Ω(readFile(includeFilePath) + "\n").Should(Equal(readFile(testDataDir, ".toolbox.mk.content.expected"))) }) - It("should generate a correct output", func() { - out := &bytes.Buffer{} - path := copyFile("Makefile.content", tempDir) - err := Generate(resty.New(), out, path, false, "", + It("should migrate to include correct output", func() { + makeFilePath = copyFile("Makefile.content.migrate", tempDir) + err := Generate(resty.New(), makeFilePath, false, "", "sigs.k8s.io/controller-tools/cmd/controller-gen@github.com/kubernetes-sigs/controller-tools", "github.com/bakito/semver", "github.com/bakito/toolbox", ) Ω(err).ShouldNot(HaveOccurred()) - Ω(out.Bytes()).Should(BeEmpty()) - Ω(readFile(path)).Should(Equal(readFile(testDataDir, "Makefile.content.expected"))) + Ω(readFile(makeFilePath)).Should(Equal(readFile(testDataDir, "Makefile.content.expected"))) + Ω(readFile(includeFilePath) + "\n").Should(Equal(readFile(testDataDir, ".toolbox.mk.content.expected"))) }) It("should generate a correct output wit hybrid tools", func() { - out := &bytes.Buffer{} - - err := Generate(resty.New(), out, "", false, + err := Generate(resty.New(), makeFilePath, false, filepath.Join(testDataDir, "tools.go.tst"), "sigs.k8s.io/controller-tools/cmd/controller-gen@github.com/kubernetes-sigs/controller-tools", "github.com/bakito/toolbox", ) Ω(err).ShouldNot(HaveOccurred()) - Ω(out.String() + "\n").Should(Equal(readFile(testDataDir, "Makefile.hybrid.expected"))) + Ω(readFile(makeFilePath)).Should(Equal(readFile(testDataDir, "Makefile.content.expected"))) + Ω(readFile(includeFilePath) + "\n").Should(Equal(readFile(testDataDir, ".toolbox.mk.hybrid.expected"))) }) It("should generate a correct output with renovate enabled", func() { - out := &bytes.Buffer{} - err := Generate(resty.New(), out, "", true, "", + err := Generate(resty.New(), makeFilePath, true, "", "sigs.k8s.io/controller-tools/cmd/controller-gen@github.com/kubernetes-sigs/controller-tools", "github.com/bakito/semver", "github.com/bakito/toolbox", ) Ω(err).ShouldNot(HaveOccurred()) - Ω(out.String() + "\n").Should(Equal(readFile(testDataDir, "Makefile.renovate.expected"))) + Ω(readFile(makeFilePath)).Should(Equal(readFile(testDataDir, "Makefile.content.expected"))) + Ω(readFile(includeFilePath) + "\n").Should(Equal(readFile(testDataDir, ".toolbox.mk.renovate.expected"))) }) }) Context("generate", func() { It("should generate a correct output", func() { - out := &bytes.Buffer{} - td := []toolData{ dataForTool(true, "sigs.k8s.io/controller-tools/cmd/controller-gen"), dataForTool(true, "github.com/bakito/semver"), dataForTool(true, "github.com/bakito/toolbox"), } - err := generate(resty.New(), out, "", false, nil, td) + err := generate(resty.New(), makeFilePath, false, nil, td) Ω(err).ShouldNot(HaveOccurred()) - Ω(out.String() + "\n").Should(Equal(readFile(testDataDir, "Makefile.tools.go.expected"))) + Ω(readFile(makeFilePath)).Should(Equal(readFile(testDataDir, "Makefile.content.expected"))) + Ω(readFile(includeFilePath) + "\n").Should(Equal(readFile(testDataDir, ".toolbox.mk.tools.go.expected"))) }) }) Context("updateRenovateConfInternal", func() { It("should add a customManagers section", func() { - cfg, err := updateRenovateConfInternal(filepath.Join(testDataDir, "renovate.no-managers.json")) + withRenovate, cfg, err := updateRenovateConfInternal(filepath.Join(testDataDir, "renovate.no-managers.json")) Ω(err).ShouldNot(HaveOccurred()) + Ω(withRenovate).Should(BeTrue()) Ω(string(cfg)).Should(Equal(readFile(testDataDir, "renovate.no-managers.expected.json"))) }) It("should add the toolbox customManager", func() { - cfg, err := updateRenovateConfInternal(filepath.Join(testDataDir, "renovate.other-managers.json")) + withRenovate, cfg, err := updateRenovateConfInternal(filepath.Join(testDataDir, "renovate.other-managers.json")) Ω(err).ShouldNot(HaveOccurred()) + Ω(withRenovate).Should(BeTrue()) Ω(string(cfg)).Should(Equal(readFile(testDataDir, "renovate.other-managers.expected.json"))) }) It("should update the toolbox customManager", func() { - cfg, err := updateRenovateConfInternal(filepath.Join(testDataDir, "renovate.incorrect-managers.json")) + withRenovate, cfg, err := updateRenovateConfInternal(filepath.Join(testDataDir, "renovate.incorrect-managers.json")) Ω(err).ShouldNot(HaveOccurred()) + Ω(withRenovate).Should(BeTrue()) Ω(string(cfg)).Should(Equal(readFile(testDataDir, "renovate.incorrect-managers.expected.json"))) }) }) diff --git a/pkg/makefile/renovate.go b/pkg/makefile/renovate.go index 5fb5707..582b198 100644 --- a/pkg/makefile/renovate.go +++ b/pkg/makefile/renovate.go @@ -12,28 +12,28 @@ import ( const renovateJson = "renovate.json" func updateRenovateConf() error { - cfg, err := updateRenovateConfInternal(renovateJson) - if err != nil { + withRenovate, cfg, err := updateRenovateConfInternal(renovateJson) + if err != nil || !withRenovate { return err } return os.WriteFile(renovateJson, cfg, 0o600) } -func updateRenovateConfInternal(renovateCfgFile string) ([]byte, error) { +func updateRenovateConfInternal(renovateCfgFile string) (bool, []byte, error) { if _, err := os.Stat(renovateCfgFile); errors.Is(err, os.ErrNotExist) { // no renovate config found, abort - return nil, nil + return false, nil, nil } renovateCfg, err := readRenovateConfig(renovateCfgFile) if err != nil { - return nil, err + return false, nil, err } cms := renovate.CustomManagers{} if cm, ok := renovateCfg["customManagers"]; ok { if err := covert(&cm, &cms); err != nil { - return nil, err + return false, nil, err } found := false @@ -55,11 +55,12 @@ func updateRenovateConfInternal(renovateCfgFile string) ([]byte, error) { var merged []map[string]interface{} if err := covert(&cms, &merged); err != nil { - return nil, err + return false, nil, err } renovateCfg["customManagers"] = merged - return prettyPrint(renovateCfg) + pp, err := prettyPrint(renovateCfg) + return true, pp, err } func covert(from interface{}, to interface{}) error { diff --git a/testdata/.toolbox.mk.content.expected b/testdata/.toolbox.mk.content.expected new file mode 100644 index 0000000..a8fa724 --- /dev/null +++ b/testdata/.toolbox.mk.content.expected @@ -0,0 +1,44 @@ +## toolbox - start +## Current working directory +TB_LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd) +## Location to install dependencies to +TB_LOCALBIN ?= $(TB_LOCALDIR)/bin +$(TB_LOCALBIN): + mkdir -p $(TB_LOCALBIN) + +## Tool Binaries +TB_CONTROLLER_GEN ?= $(TB_LOCALBIN)/controller-gen +TB_SEMVER ?= $(TB_LOCALBIN)/semver +TB_TOOLBOX ?= $(TB_LOCALBIN)/toolbox + +## Tool Versions +TB_CONTROLLER_GEN_VERSION ?= v0.2.1 +TB_SEMVER_VERSION ?= v0.2.1 +TB_TOOLBOX_VERSION ?= v0.2.1 + +## Tool Installer +.PHONY: tb.controller-gen +tb.controller-gen: $(TB_CONTROLLER_GEN) ## Download controller-gen locally if necessary. +$(TB_CONTROLLER_GEN): $(TB_LOCALBIN) + test -s $(TB_LOCALBIN)/controller-gen || GOBIN=$(TB_LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(TB_CONTROLLER_GEN_VERSION) +.PHONY: tb.semver +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) +.PHONY: tb.toolbox +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: + @rm -f \ + $(TB_LOCALBIN)/controller-gen \ + $(TB_LOCALBIN)/semver \ + $(TB_LOCALBIN)/toolbox + toolbox makefile -f $(TB_LOCALDIR)/Makefile \ + sigs.k8s.io/controller-tools/cmd/controller-gen@github.com/kubernetes-sigs/controller-tools \ + github.com/bakito/semver \ + github.com/bakito/toolbox +## toolbox - end diff --git a/testdata/.toolbox.mk.hybrid.expected b/testdata/.toolbox.mk.hybrid.expected new file mode 100644 index 0000000..604c334 --- /dev/null +++ b/testdata/.toolbox.mk.hybrid.expected @@ -0,0 +1,42 @@ +## toolbox - start +## Current working directory +TB_LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd) +## Location to install dependencies to +TB_LOCALBIN ?= $(TB_LOCALDIR)/bin +$(TB_LOCALBIN): + mkdir -p $(TB_LOCALBIN) + +## Tool Binaries +TB_CONTROLLER_GEN ?= $(TB_LOCALBIN)/controller-gen +TB_SEMVER ?= $(TB_LOCALBIN)/semver +TB_TOOLBOX ?= $(TB_LOCALBIN)/toolbox + +## Tool Versions +TB_CONTROLLER_GEN_VERSION ?= v0.2.1 +TB_TOOLBOX_VERSION ?= v0.2.1 + +## Tool Installer +.PHONY: tb.controller-gen +tb.controller-gen: $(TB_CONTROLLER_GEN) ## Download controller-gen locally if necessary. +$(TB_CONTROLLER_GEN): $(TB_LOCALBIN) + test -s $(TB_LOCALBIN)/controller-gen || GOBIN=$(TB_LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(TB_CONTROLLER_GEN_VERSION) +.PHONY: tb.semver +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 +.PHONY: tb.toolbox +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: + @rm -f \ + $(TB_LOCALBIN)/controller-gen \ + $(TB_LOCALBIN)/semver \ + $(TB_LOCALBIN)/toolbox + toolbox makefile -f $(TB_LOCALDIR)/Makefile \ + sigs.k8s.io/controller-tools/cmd/controller-gen@github.com/kubernetes-sigs/controller-tools \ + github.com/bakito/toolbox +## toolbox - end diff --git a/testdata/.toolbox.mk.renovate.expected b/testdata/.toolbox.mk.renovate.expected new file mode 100644 index 0000000..2693a08 --- /dev/null +++ b/testdata/.toolbox.mk.renovate.expected @@ -0,0 +1,47 @@ +## toolbox - start +## Current working directory +TB_LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd) +## Location to install dependencies to +TB_LOCALBIN ?= $(TB_LOCALDIR)/bin +$(TB_LOCALBIN): + mkdir -p $(TB_LOCALBIN) + +## Tool Binaries +TB_CONTROLLER_GEN ?= $(TB_LOCALBIN)/controller-gen +TB_SEMVER ?= $(TB_LOCALBIN)/semver +TB_TOOLBOX ?= $(TB_LOCALBIN)/toolbox + +## Tool Versions +# renovate: packageName=sigs.k8s.io/controller-tools/cmd/controller-gen +TB_CONTROLLER_GEN_VERSION ?= v0.2.1 +# renovate: packageName=github.com/bakito/semver +TB_SEMVER_VERSION ?= v0.2.1 +# renovate: packageName=github.com/bakito/toolbox +TB_TOOLBOX_VERSION ?= v0.2.1 + +## Tool Installer +.PHONY: tb.controller-gen +tb.controller-gen: $(TB_CONTROLLER_GEN) ## Download controller-gen locally if necessary. +$(TB_CONTROLLER_GEN): $(TB_LOCALBIN) + test -s $(TB_LOCALBIN)/controller-gen || GOBIN=$(TB_LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(TB_CONTROLLER_GEN_VERSION) +.PHONY: tb.semver +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) +.PHONY: tb.toolbox +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: + @rm -f \ + $(TB_LOCALBIN)/controller-gen \ + $(TB_LOCALBIN)/semver \ + $(TB_LOCALBIN)/toolbox + 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 \ + github.com/bakito/toolbox +## toolbox - end diff --git a/testdata/.toolbox.mk.tools.go.expected b/testdata/.toolbox.mk.tools.go.expected new file mode 100644 index 0000000..55866ef --- /dev/null +++ b/testdata/.toolbox.mk.tools.go.expected @@ -0,0 +1,36 @@ +## toolbox - start +## Current working directory +TB_LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd) +## Location to install dependencies to +TB_LOCALBIN ?= $(TB_LOCALDIR)/bin +$(TB_LOCALBIN): + mkdir -p $(TB_LOCALBIN) + +## Tool Binaries +TB_CONTROLLER_GEN ?= $(TB_LOCALBIN)/controller-gen +TB_SEMVER ?= $(TB_LOCALBIN)/semver +TB_TOOLBOX ?= $(TB_LOCALBIN)/toolbox + +## Tool Installer +.PHONY: tb.controller-gen +tb.controller-gen: $(TB_CONTROLLER_GEN) ## Download controller-gen locally if necessary. +$(TB_CONTROLLER_GEN): $(TB_LOCALBIN) + test -s $(TB_LOCALBIN)/controller-gen || GOBIN=$(TB_LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen +.PHONY: tb.semver +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 +.PHONY: tb.toolbox +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: + @rm -f \ + $(TB_LOCALBIN)/controller-gen \ + $(TB_LOCALBIN)/semver \ + $(TB_LOCALBIN)/toolbox + toolbox makefile -f $(TB_LOCALDIR)/Makefile +## toolbox - end diff --git a/testdata/Makefile.content b/testdata/Makefile.content index 315d7c1..ca81eca 100644 --- a/testdata/Makefile.content +++ b/testdata/Makefile.content @@ -1,6 +1,2 @@ -... - -## toolbox - start -## toolbox - end - -... +foo: + @echo "bar" diff --git a/testdata/Makefile.content.expected b/testdata/Makefile.content.expected index a1746c2..94615a0 100644 --- a/testdata/Makefile.content.expected +++ b/testdata/Makefile.content.expected @@ -1,48 +1,5 @@ -... +# Include toolbox tasks +include ./.toolbox.mk -## toolbox - start -## Current working directory -LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd) -## Location to install dependencies to -LOCALBIN ?= $(LOCALDIR)/bin -$(LOCALBIN): - mkdir -p $(LOCALBIN) - -## Tool Binaries -CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen -SEMVER ?= $(LOCALBIN)/semver -TOOLBOX ?= $(LOCALBIN)/toolbox - -## Tool Versions -CONTROLLER_GEN_VERSION ?= v0.2.1 -SEMVER_VERSION ?= v0.2.1 -TOOLBOX_VERSION ?= v0.2.1 - -## Tool Installer -.PHONY: controller-gen -controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. -$(CONTROLLER_GEN): $(LOCALBIN) - test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) -.PHONY: semver -semver: $(SEMVER) ## Download semver locally if necessary. -$(SEMVER): $(LOCALBIN) - test -s $(LOCALBIN)/semver || GOBIN=$(LOCALBIN) go install github.com/bakito/semver@$(SEMVER_VERSION) -.PHONY: toolbox -toolbox: $(TOOLBOX) ## Download toolbox locally if necessary. -$(TOOLBOX): $(LOCALBIN) - test -s $(LOCALBIN)/toolbox || GOBIN=$(LOCALBIN) go install github.com/bakito/toolbox@$(TOOLBOX_VERSION) - -## Update Tools -.PHONY: update-toolbox-tools -update-toolbox-tools: - @rm -f \ - $(LOCALBIN)/controller-gen \ - $(LOCALBIN)/semver \ - $(LOCALBIN)/toolbox - toolbox makefile -f $(LOCALDIR)/Makefile \ - sigs.k8s.io/controller-tools/cmd/controller-gen@github.com/kubernetes-sigs/controller-tools \ - github.com/bakito/semver \ - github.com/bakito/toolbox -## toolbox - end - -... +foo: + @echo "bar" diff --git a/testdata/Makefile.content.migrate b/testdata/Makefile.content.migrate new file mode 100644 index 0000000..218013f --- /dev/null +++ b/testdata/Makefile.content.migrate @@ -0,0 +1,4 @@ +foo: + @echo "bar" +## toolbox - start +## toolbox - end diff --git a/testdata/Makefile.expected b/testdata/Makefile.expected deleted file mode 100644 index ffddd82..0000000 --- a/testdata/Makefile.expected +++ /dev/null @@ -1,44 +0,0 @@ -## toolbox - start -## Current working directory -LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd) -## Location to install dependencies to -LOCALBIN ?= $(LOCALDIR)/bin -$(LOCALBIN): - mkdir -p $(LOCALBIN) - -## Tool Binaries -CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen -SEMVER ?= $(LOCALBIN)/semver -TOOLBOX ?= $(LOCALBIN)/toolbox - -## Tool Versions -CONTROLLER_GEN_VERSION ?= v0.2.1 -SEMVER_VERSION ?= v0.2.1 -TOOLBOX_VERSION ?= v0.2.1 - -## Tool Installer -.PHONY: controller-gen -controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. -$(CONTROLLER_GEN): $(LOCALBIN) - test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) -.PHONY: semver -semver: $(SEMVER) ## Download semver locally if necessary. -$(SEMVER): $(LOCALBIN) - test -s $(LOCALBIN)/semver || GOBIN=$(LOCALBIN) go install github.com/bakito/semver@$(SEMVER_VERSION) -.PHONY: toolbox -toolbox: $(TOOLBOX) ## Download toolbox locally if necessary. -$(TOOLBOX): $(LOCALBIN) - test -s $(LOCALBIN)/toolbox || GOBIN=$(LOCALBIN) go install github.com/bakito/toolbox@$(TOOLBOX_VERSION) - -## Update Tools -.PHONY: update-toolbox-tools -update-toolbox-tools: - @rm -f \ - $(LOCALBIN)/controller-gen \ - $(LOCALBIN)/semver \ - $(LOCALBIN)/toolbox - toolbox makefile -f $(LOCALDIR)/Makefile \ - sigs.k8s.io/controller-tools/cmd/controller-gen@github.com/kubernetes-sigs/controller-tools \ - github.com/bakito/semver \ - github.com/bakito/toolbox -## toolbox - end diff --git a/testdata/Makefile.hybrid.expected b/testdata/Makefile.hybrid.expected deleted file mode 100644 index 1028c25..0000000 --- a/testdata/Makefile.hybrid.expected +++ /dev/null @@ -1,42 +0,0 @@ -## toolbox - start -## Current working directory -LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd) -## Location to install dependencies to -LOCALBIN ?= $(LOCALDIR)/bin -$(LOCALBIN): - mkdir -p $(LOCALBIN) - -## Tool Binaries -CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen -SEMVER ?= $(LOCALBIN)/semver -TOOLBOX ?= $(LOCALBIN)/toolbox - -## Tool Versions -CONTROLLER_GEN_VERSION ?= v0.2.1 -TOOLBOX_VERSION ?= v0.2.1 - -## Tool Installer -.PHONY: controller-gen -controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. -$(CONTROLLER_GEN): $(LOCALBIN) - test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) -.PHONY: semver -semver: $(SEMVER) ## Download semver locally if necessary. -$(SEMVER): $(LOCALBIN) - test -s $(LOCALBIN)/semver || GOBIN=$(LOCALBIN) go install github.com/bakito/semver -.PHONY: toolbox -toolbox: $(TOOLBOX) ## Download toolbox locally if necessary. -$(TOOLBOX): $(LOCALBIN) - test -s $(LOCALBIN)/toolbox || GOBIN=$(LOCALBIN) go install github.com/bakito/toolbox@$(TOOLBOX_VERSION) - -## Update Tools -.PHONY: update-toolbox-tools -update-toolbox-tools: - @rm -f \ - $(LOCALBIN)/controller-gen \ - $(LOCALBIN)/semver \ - $(LOCALBIN)/toolbox - toolbox makefile -f $(LOCALDIR)/Makefile \ - sigs.k8s.io/controller-tools/cmd/controller-gen@github.com/kubernetes-sigs/controller-tools \ - github.com/bakito/toolbox -## toolbox - end diff --git a/testdata/Makefile.renovate.expected b/testdata/Makefile.renovate.expected deleted file mode 100644 index fcc1a17..0000000 --- a/testdata/Makefile.renovate.expected +++ /dev/null @@ -1,47 +0,0 @@ -## toolbox - start -## Current working directory -LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd) -## Location to install dependencies to -LOCALBIN ?= $(LOCALDIR)/bin -$(LOCALBIN): - mkdir -p $(LOCALBIN) - -## Tool Binaries -CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen -SEMVER ?= $(LOCALBIN)/semver -TOOLBOX ?= $(LOCALBIN)/toolbox - -## Tool Versions -# renovate: packageName=sigs.k8s.io/controller-tools/cmd/controller-gen -CONTROLLER_GEN_VERSION ?= v0.2.1 -# renovate: packageName=github.com/bakito/semver -SEMVER_VERSION ?= v0.2.1 -# renovate: packageName=github.com/bakito/toolbox -TOOLBOX_VERSION ?= v0.2.1 - -## Tool Installer -.PHONY: controller-gen -controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. -$(CONTROLLER_GEN): $(LOCALBIN) - test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) -.PHONY: semver -semver: $(SEMVER) ## Download semver locally if necessary. -$(SEMVER): $(LOCALBIN) - test -s $(LOCALBIN)/semver || GOBIN=$(LOCALBIN) go install github.com/bakito/semver@$(SEMVER_VERSION) -.PHONY: toolbox -toolbox: $(TOOLBOX) ## Download toolbox locally if necessary. -$(TOOLBOX): $(LOCALBIN) - test -s $(LOCALBIN)/toolbox || GOBIN=$(LOCALBIN) go install github.com/bakito/toolbox@$(TOOLBOX_VERSION) - -## Update Tools -.PHONY: update-toolbox-tools -update-toolbox-tools: - @rm -f \ - $(LOCALBIN)/controller-gen \ - $(LOCALBIN)/semver \ - $(LOCALBIN)/toolbox - toolbox makefile --renovate -f $(LOCALDIR)/Makefile \ - sigs.k8s.io/controller-tools/cmd/controller-gen@github.com/kubernetes-sigs/controller-tools \ - github.com/bakito/semver \ - github.com/bakito/toolbox -## toolbox - end diff --git a/testdata/Makefile.tools.go.expected b/testdata/Makefile.tools.go.expected deleted file mode 100644 index 42f3962..0000000 --- a/testdata/Makefile.tools.go.expected +++ /dev/null @@ -1,36 +0,0 @@ -## toolbox - start -## Current working directory -LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd) -## Location to install dependencies to -LOCALBIN ?= $(LOCALDIR)/bin -$(LOCALBIN): - mkdir -p $(LOCALBIN) - -## Tool Binaries -CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen -SEMVER ?= $(LOCALBIN)/semver -TOOLBOX ?= $(LOCALBIN)/toolbox - -## Tool Installer -.PHONY: controller-gen -controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. -$(CONTROLLER_GEN): $(LOCALBIN) - test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen -.PHONY: semver -semver: $(SEMVER) ## Download semver locally if necessary. -$(SEMVER): $(LOCALBIN) - test -s $(LOCALBIN)/semver || GOBIN=$(LOCALBIN) go install github.com/bakito/semver -.PHONY: toolbox -toolbox: $(TOOLBOX) ## Download toolbox locally if necessary. -$(TOOLBOX): $(LOCALBIN) - test -s $(LOCALBIN)/toolbox || GOBIN=$(LOCALBIN) go install github.com/bakito/toolbox - -## Update Tools -.PHONY: update-toolbox-tools -update-toolbox-tools: - @rm -f \ - $(LOCALBIN)/controller-gen \ - $(LOCALBIN)/semver \ - $(LOCALBIN)/toolbox - toolbox makefile -f $(LOCALDIR)/Makefile -## toolbox - end