Skip to content

Commit b32fb44

Browse files
authored
Merge pull request #243 from sapcc/feat/customManagers
feat(renovate): add customManagers and extend packageRules
1 parent f2d80f2 commit b32fb44

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,12 @@ renovate:
283283
matchUpdateTypes: []
284284
matchDepTypes: []
285285
matchFileNames: []
286+
extends: []
286287
allowedVersions: ""
288+
minimumReleaseAge: ""
287289
autoMerge: false
288290
enabled: false
291+
customManagers: []
289292
```
290293

291294
Generate [RenovateBot](https://renovatebot.com/) config to automatically create pull requests weekly on Fridays with dependency updates.
@@ -319,6 +322,23 @@ packageRules:
319322
enabled: false # see docker config section above
320323
```
321324
325+
You can also define [`customManagers`](https://docs.renovatebot.com/modules/manager/regex/). An example to detect `ENVTEST_K8S_VERSION` env variable version and update it in `Makefile`
326+
327+
```yaml
328+
customManagers:
329+
- customType: "regex"
330+
description: "Bump envtest version in the Makefile"
331+
fileMatch: [
332+
"^Makefile$"
333+
]
334+
matchStrings: [
335+
"ENVTEST_K8S_VERSION\\s*\\?=\\s*(?<currentValue>.?(?:\\d+\\.){0,2}\\d+)"
336+
]
337+
datasourceTemplate: "github-tags"
338+
depNameTemplate: "kubernetes-sigs/controller-tools"
339+
extractVersionTemplate: "^envtest.v(?<version>.*)$"
340+
```
341+
322342
### `spellCheck`
323343

324344
```yaml

internal/core/config.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,21 @@ type PackageRule struct {
164164
MatchUpdateTypes []string `yaml:"matchUpdateTypes" json:"matchUpdateTypes,omitempty"`
165165
MatchDepTypes []string `yaml:"matchDepTypes" json:"matchDepTypes,omitempty"`
166166
MatchFileNames []string `yaml:"matchFileNames" json:"matchFileNames,omitempty"`
167+
Extends []string `yaml:"extends" json:"extends,omitempty"`
167168
AllowedVersions string `yaml:"allowedVersions" json:"allowedVersions,omitempty"`
168169
AutoMerge bool `yaml:"automerge" json:"automerge,omitempty"`
169170
EnableRenovate *bool `yaml:"enabled" json:"enabled,omitempty"`
170171
GroupName string `yaml:"groupName" json:"groupName,omitempty"`
172+
MinimumReleaseAge string `yaml:"minimumReleaseAge" json:"minimumReleaseAge,omitempty"`
171173
}
172174

173175
// RenovateConfig appears in type Configuration.
174176
type RenovateConfig struct {
175-
Enabled bool `yaml:"enabled"`
176-
Assignees []string `yaml:"assignees"`
177-
GoVersion string `yaml:"goVersion"`
178-
PackageRules []PackageRule `yaml:"packageRules"`
177+
Enabled bool `yaml:"enabled"`
178+
Assignees []string `yaml:"assignees"`
179+
GoVersion string `yaml:"goVersion"`
180+
PackageRules []PackageRule `yaml:"packageRules"`
181+
CustomManagers []interface{} `yaml:"customManagers"`
179182
}
180183

181184
// DockerfileConfig appears in type Configuration.

internal/renovate/renovate.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@ type config struct {
2828
OsvVulnerabilityAlerts bool `json:"osvVulnerabilityAlerts,omitempty"`
2929
PostUpdateOptions []string `json:"postUpdateOptions,omitempty"`
3030
PackageRules []core.PackageRule `json:"packageRules,omitempty"`
31+
CustomManagers []interface{} `json:"customManagers,omitempty"`
3132
PrHourlyLimit int `json:"prHourlyLimit"`
3233
Schedule []string `json:"schedule,omitempty"`
3334
SemanticCommits string `json:"semanticCommits,omitempty"`
3435
}
3536

36-
func (c *config) addPackageRule(rule core.PackageRule) {
37-
c.PackageRules = append(c.PackageRules, rule)
38-
}
39-
4037
func RenderConfig(cfgRenovate core.RenovateConfig, scanResult golang.ScanResult, url string, isApplicationRepo bool) {
4138
isGoMakefileMakerRepo := scanResult.ModulePath == "github.com/sapcc/go-makefile-maker"
4239
isInternalRenovate := strings.HasPrefix(url, "https://github.wdf.sap.corp")
@@ -90,20 +87,20 @@ func RenderConfig(cfgRenovate core.RenovateConfig, scanResult golang.ScanResult,
9087
//
9188
// NOTE: When changing this list, please also adjust the documentation for
9289
// default package rules in the README.
93-
cfg.addPackageRule(core.PackageRule{
90+
cfg.PackageRules = append(cfg.PackageRules, core.PackageRule{
9491
MatchPackageNames: []string{"golang"},
9592
AllowedVersions: cfgRenovate.GoVersion + ".x",
9693
})
9794

9895
// combine and automerge all dependencies under github.com/sapcc/
99-
cfg.addPackageRule(core.PackageRule{
96+
cfg.PackageRules = append(cfg.PackageRules, core.PackageRule{
10097
MatchPackageNames: []string{`/^github\.com\/sapcc\/.*/`},
10198
GroupName: "github.com/sapcc",
10299
AutoMerge: true,
103100
})
104101

105102
// combine all dependencies not under github.com/sapcc/
106-
cfg.addPackageRule(core.PackageRule{
103+
cfg.PackageRules = append(cfg.PackageRules, core.PackageRule{
107104
MatchPackageNames: []string{`!/^github\.com\/sapcc\/.*/`, `/.*/`},
108105
GroupName: "External dependencies",
109106
AutoMerge: false,
@@ -123,7 +120,7 @@ func RenderConfig(cfgRenovate core.RenovateConfig, scanResult golang.ScanResult,
123120
}
124121
}
125122
if hasK8sIOPkgs {
126-
cfg.addPackageRule(core.PackageRule{
123+
cfg.PackageRules = append(cfg.PackageRules, core.PackageRule{
127124
MatchPackageNames: []string{`/^k8s.io\//`},
128125
// Since our clusters use k8s v1.26 and k8s has a support policy of -/+ 1 minor version we set the allowedVersions to `0.27.x`.
129126
// k8s.io/* deps use v0.x.y instead of v1.x.y therefore we use 0.x instead of 1.x.
@@ -138,9 +135,13 @@ func RenderConfig(cfgRenovate core.RenovateConfig, scanResult golang.ScanResult,
138135
// Renovate will evaluate all packageRules and not stop once it gets a first match
139136
// therefore the packageRules should be in the order of importance so that user
140137
// defined rules can override settings from earlier rules.
141-
for _, rule := range cfgRenovate.PackageRules {
142-
cfg.addPackageRule(rule)
143-
}
138+
cfg.PackageRules = append(cfg.PackageRules, cfgRenovate.PackageRules...)
139+
140+
// CustomManagers specified in config.
141+
//
142+
// With customManagers using regex you can configure Renovate so it finds dependencies
143+
// that are not detected by its other built-in package managers.
144+
cfg.CustomManagers = append(cfg.CustomManagers, cfgRenovate.CustomManagers...)
144145

145146
must.Succeed(os.MkdirAll(".github", 0750))
146147
must.Succeed(os.RemoveAll("renovate.json"))

0 commit comments

Comments
 (0)