Skip to content

Commit 679d6e2

Browse files
committed
renovate support for Makefile
1 parent 67a48b1 commit 679d6e2

File tree

12 files changed

+64
-160
lines changed

12 files changed

+64
-160
lines changed

.golangci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ linters:
99
- durationcheck
1010
- errcheck
1111
- errorlint
12-
- exportloopref
1312
- gci
1413
- gofmt
1514
- gofumpt

Makefile

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ DEEPCOPY_GEN ?= $(LOCALBIN)/deepcopy-gen
3131
GINKGO ?= $(LOCALBIN)/ginkgo
3232
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
3333
GORELEASER ?= $(LOCALBIN)/goreleaser
34-
OAPI_CODEGEN ?= $(LOCALBIN)/oapi-codegen
3534
SEMVER ?= $(LOCALBIN)/semver
3635

3736
## Tool Versions
38-
DEEPCOPY_GEN_VERSION ?= v0.30.3
39-
GORELEASER_VERSION ?= v2.1.0
40-
OAPI_CODEGEN_VERSION ?= v2.3.0
37+
# renovate: packageName=k8s.io/code-generator/cmd/deepcopy-gen
38+
DEEPCOPY_GEN_VERSION ?= v0.31.1
39+
# renovate: packageName=github.com/goreleaser/goreleaser/v2
40+
GORELEASER_VERSION ?= v2.3.2
4141

4242
## Tool Installer
4343
.PHONY: deepcopy-gen
@@ -56,10 +56,6 @@ $(GOLANGCI_LINT): $(LOCALBIN)
5656
goreleaser: $(GORELEASER) ## Download goreleaser locally if necessary.
5757
$(GORELEASER): $(LOCALBIN)
5858
test -s $(LOCALBIN)/goreleaser || GOBIN=$(LOCALBIN) go install github.com/goreleaser/goreleaser/v2@$(GORELEASER_VERSION)
59-
.PHONY: oapi-codegen
60-
oapi-codegen: $(OAPI_CODEGEN) ## Download oapi-codegen locally if necessary.
61-
$(OAPI_CODEGEN): $(LOCALBIN)
62-
test -s $(LOCALBIN)/oapi-codegen || GOBIN=$(LOCALBIN) go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@$(OAPI_CODEGEN_VERSION)
6359
.PHONY: semver
6460
semver: $(SEMVER) ## Download semver locally if necessary.
6561
$(SEMVER): $(LOCALBIN)
@@ -73,10 +69,8 @@ update-toolbox-tools:
7369
$(LOCALBIN)/ginkgo \
7470
$(LOCALBIN)/golangci-lint \
7571
$(LOCALBIN)/goreleaser \
76-
$(LOCALBIN)/oapi-codegen \
7772
$(LOCALBIN)/semver
7873
toolbox makefile -f $(LOCALDIR)/Makefile \
7974
k8s.io/code-generator/cmd/[email protected]/kubernetes/code-generator \
80-
github.com/goreleaser/goreleaser/v2 \
81-
github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen
75+
github.com/goreleaser/goreleaser/v2
8276
## toolbox - end

cmd/makefile.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,26 @@ const (
1515
)
1616

1717
var (
18-
toolsGo string
18+
toolsGo string
19+
renovate bool
1920
// makefileCmd represents the makefile command
2021
makefileCmd = &cobra.Command{
2122
Use: "makefile [tools]",
2223
Short: "Adds tools to a Makefile",
2324
Args: func(_ *cobra.Command, args []string) error {
24-
if _, err := os.Stat(toolsGo); err != nil {
25+
if _, err := os.Stat(toolsGo); err != nil && !renovate {
2526
if len(args) == 0 {
2627
return errors.New("at least one tool must be provided")
2728
}
2829
}
2930
return nil
3031
},
3132
RunE: func(cmd *cobra.Command, args []string) error {
33+
if renovate {
34+
makefile.PrintRenovateConfig(cmd.OutOrStderr())
35+
return nil
36+
}
37+
3238
client := resty.New()
3339
mf, err := cmd.Flags().GetString(flagFile)
3440
if err != nil {
@@ -43,5 +49,6 @@ func init() {
4349
rootCmd.AddCommand(makefileCmd)
4450

4551
makefileCmd.Flags().StringP(flagFile, "f", "", "The Makefile path to generate tools in")
46-
makefileCmd.Flags().StringVar(&toolsGo, flagToolsGo, "tools.go", "The tools.go file to check for tools dependencies.")
52+
makefileCmd.Flags().StringVar(&toolsGo, flagToolsGo, "tools.go", "The tools.go file to check for tools dependencies")
53+
makefileCmd.Flags().BoolVar(&renovate, "renovate", false, "Print sample renovate config for Makefile")
4754
}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ require (
165165
github.com/stretchr/objx v0.5.2 // indirect
166166
github.com/stretchr/testify v1.9.0 // indirect
167167
github.com/subosito/gotenv v1.6.0 // indirect
168-
github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect
169168
github.com/tdakkota/asciicheck v0.2.0 // indirect
170169
github.com/tetafro/godot v1.4.17 // indirect
171170
github.com/timakin/bodyclose v0.0.0-20230421092635-574207250966 // indirect

go.sum

Lines changed: 4 additions & 143 deletions
Large diffs are not rendered by default.

pkg/makefile/Makefile.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ $(LOCALBIN):
1414
## Tool Versions
1515
{{- range .Tools }}
1616
{{- if .Version }}
17+
# renovate: packageName={{.ToolName}}
1718
{{.UpperName}}_VERSION ?= {{.Version}}
1819
{{- end }}
1920
{{- end }}

pkg/makefile/consts.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@ import (
88
const (
99
markerStart = "## toolbox - start"
1010
markerEnd = "## toolbox - end"
11+
12+
renovateConfig = `{
13+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
14+
"customManagers": [
15+
{
16+
"customType": "regex",
17+
"description": "Update toolbox _VERSION variables in Makefile",
18+
"fileMatch": [
19+
"Makefile"
20+
],
21+
"matchStrings": [
22+
"# renovate: packageName=(?<packageName>.+?)\\s+.+?_VERSION \\?= (?<currentValue>.+?)\\s"
23+
],
24+
"datasourceTemplate": "go"
25+
}
26+
]
27+
}
28+
`
1129
)
1230

1331
var (

pkg/makefile/make.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,7 @@ func unique(slice []string) []string {
172172
slices.Sort(uniqSlice)
173173
return uniqSlice
174174
}
175+
176+
func PrintRenovateConfig(out io.Writer) {
177+
_, _ = out.Write([]byte(renovateConfig))
178+
}

renovate.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
{
22
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3-
"dependencyDashboard": true
3+
"dependencyDashboard": true,
4+
"customManagers": [
5+
{
6+
"customType": "regex",
7+
"description": "Update toolbox _VERSION variables in Makefile",
8+
"fileMatch": [
9+
"Makefile"
10+
],
11+
"matchStrings": [
12+
"# renovate: packageName=(?<packageName>.+?)\\s+.+?_VERSION \\?= (?<currentValue>.+?)\\s"
13+
],
14+
"datasourceTemplate": "go"
15+
}
16+
]
417
}

testdata/Makefile.content.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ SEMVER ?= $(LOCALBIN)/semver
1414
TOOLBOX ?= $(LOCALBIN)/toolbox
1515

1616
## Tool Versions
17+
# renovate: packageName=sigs.k8s.io/controller-tools/cmd/controller-gen
1718
CONTROLLER_GEN_VERSION ?= v0.2.1
19+
# renovate: packageName=github.com/bakito/semver
1820
SEMVER_VERSION ?= v0.2.1
21+
# renovate: packageName=github.com/bakito/toolbox
1922
TOOLBOX_VERSION ?= v0.2.1
2023

2124
## Tool Installer

0 commit comments

Comments
 (0)