Skip to content

Commit

Permalink
renovate support for Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito committed Sep 27, 2024
1 parent 67a48b1 commit 679d6e2
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 160 deletions.
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ linters:
- durationcheck
- errcheck
- errorlint
- exportloopref
- gci
- gofmt
- gofumpt
Expand Down
16 changes: 5 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ DEEPCOPY_GEN ?= $(LOCALBIN)/deepcopy-gen
GINKGO ?= $(LOCALBIN)/ginkgo
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
GORELEASER ?= $(LOCALBIN)/goreleaser
OAPI_CODEGEN ?= $(LOCALBIN)/oapi-codegen
SEMVER ?= $(LOCALBIN)/semver

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

## Tool Installer
.PHONY: deepcopy-gen
Expand All @@ -56,10 +56,6 @@ $(GOLANGCI_LINT): $(LOCALBIN)
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: oapi-codegen
oapi-codegen: $(OAPI_CODEGEN) ## Download oapi-codegen locally if necessary.
$(OAPI_CODEGEN): $(LOCALBIN)
test -s $(LOCALBIN)/oapi-codegen || GOBIN=$(LOCALBIN) go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@$(OAPI_CODEGEN_VERSION)
.PHONY: semver
semver: $(SEMVER) ## Download semver locally if necessary.
$(SEMVER): $(LOCALBIN)
Expand All @@ -73,10 +69,8 @@ update-toolbox-tools:
$(LOCALBIN)/ginkgo \
$(LOCALBIN)/golangci-lint \
$(LOCALBIN)/goreleaser \
$(LOCALBIN)/oapi-codegen \
$(LOCALBIN)/semver
toolbox makefile -f $(LOCALDIR)/Makefile \
k8s.io/code-generator/cmd/deepcopy-gen@github.com/kubernetes/code-generator \
github.com/goreleaser/goreleaser/v2 \
github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen
github.com/goreleaser/goreleaser/v2
## toolbox - end
13 changes: 10 additions & 3 deletions cmd/makefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@ const (
)

var (
toolsGo string
toolsGo string
renovate bool
// makefileCmd represents the makefile command
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 _, err := os.Stat(toolsGo); err != nil && !renovate {
if len(args) == 0 {
return errors.New("at least one tool must be provided")
}
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if renovate {
makefile.PrintRenovateConfig(cmd.OutOrStderr())
return nil
}

client := resty.New()
mf, err := cmd.Flags().GetString(flagFile)
if err != nil {
Expand All @@ -43,5 +49,6 @@ func init() {
rootCmd.AddCommand(makefileCmd)

makefileCmd.Flags().StringP(flagFile, "f", "", "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().StringVar(&toolsGo, flagToolsGo, "tools.go", "The tools.go file to check for tools dependencies")
makefileCmd.Flags().BoolVar(&renovate, "renovate", false, "Print sample renovate config for Makefile")
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ require (
github.com/stretchr/objx v0.5.2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect
github.com/tdakkota/asciicheck v0.2.0 // indirect
github.com/tetafro/godot v1.4.17 // indirect
github.com/timakin/bodyclose v0.0.0-20230421092635-574207250966 // indirect
Expand Down
147 changes: 4 additions & 143 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/makefile/Makefile.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ $(LOCALBIN):
## Tool Versions
{{- range .Tools }}
{{- if .Version }}
# renovate: packageName={{.ToolName}}
{{.UpperName}}_VERSION ?= {{.Version}}
{{- end }}
{{- end }}
Expand Down
18 changes: 18 additions & 0 deletions pkg/makefile/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ import (
const (
markerStart = "## toolbox - start"
markerEnd = "## toolbox - end"

renovateConfig = `{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"customManagers": [
{
"customType": "regex",
"description": "Update toolbox _VERSION variables in Makefile",
"fileMatch": [
"Makefile"
],
"matchStrings": [
"# renovate: packageName=(?<packageName>.+?)\\s+.+?_VERSION \\?= (?<currentValue>.+?)\\s"
],
"datasourceTemplate": "go"
}
]
}
`
)

var (
Expand Down
4 changes: 4 additions & 0 deletions pkg/makefile/make.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,7 @@ func unique(slice []string) []string {
slices.Sort(uniqSlice)
return uniqSlice
}

func PrintRenovateConfig(out io.Writer) {
_, _ = out.Write([]byte(renovateConfig))
}
15 changes: 14 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"dependencyDashboard": true
"dependencyDashboard": true,
"customManagers": [
{
"customType": "regex",
"description": "Update toolbox _VERSION variables in Makefile",
"fileMatch": [
"Makefile"
],
"matchStrings": [
"# renovate: packageName=(?<packageName>.+?)\\s+.+?_VERSION \\?= (?<currentValue>.+?)\\s"
],
"datasourceTemplate": "go"
}
]
}
3 changes: 3 additions & 0 deletions testdata/Makefile.content.expected
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ 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
Expand Down
3 changes: 3 additions & 0 deletions testdata/Makefile.expected
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ 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
Expand Down
2 changes: 2 additions & 0 deletions testdata/Makefile.hybrid.expected
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ 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/toolbox
TOOLBOX_VERSION ?= v0.2.1

## Tool Installer
Expand Down

0 comments on commit 679d6e2

Please sign in to comment.