Skip to content

Commit

Permalink
feat: support renovate config
Browse files Browse the repository at this point in the history
Support managing renovate via kres so updates are easier.

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo committed Dec 16, 2024
1 parent 8183c20 commit 071772c
Show file tree
Hide file tree
Showing 17 changed files with 288 additions and 66 deletions.
73 changes: 20 additions & 53 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,85 +1,52 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"description": "THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.\n\nGenerated on 2024-12-16T13:00:41Z by kres fb2c01d-dirty.\n\n",
"prHeader": "Update Request | Renovate Bot",
"extends": [
":dependencyDashboard",
":gitSignOff",
":semanticCommitScopeDisabled",
"schedule:earlyMondays"
],
"prHeader": "Update Request | Renovate Bot",
"regexManagers": [
"customManagers": [
{
"customType": "regex",
"versioningTemplate": "{{#if versioning}}{{versioning}}{{else}}semver{{/if}}",
"fileMatch": [
"internal/config/constants.go"
],
"matchStrings": [
"\\/\\/\\s+renovate: datasource=(?<datasource>.*?)(?:\\s+extractVersion=(?<extractVersion>.+?))?(?:\\s+versioning=(?<versioning>.+?))?\\s+depName=(?<depName>.+?)?\\s.*Version\\s+=\\s+\\\"(?<currentValue>.+?)\\\""
],
"versioningTemplate": "{{#if versioning}}{{versioning}}{{else}}semver{{/if}}"
]
}
],
"packageRules": [
{
"matchPackageNames": [
"golang/go"
],
"versioning": "regex:^(?<major>\\d+)\\.(?<minor>\\d+)\\.?(?<patch>\\d+)?$"
"groupName": "dependencies",
"matchUpdateTypes": [
"major",
"minor",
"patch",
"pin",
"digest"
]
},
{
"versioning": "regex:^v(?<major>\\d+)",
"matchPackageNames": [
"actions/checkout",
"docker/login-action",
"crazy-max/ghaction-github-release",
"docker/setup-buildx-action",
"slackapi/slack-github-action"
],
"versioning": "regex:^v(?<major>\\d+)"
]
},
{
"versioning": "regex:^v(?<major>\\d+)_(?<minor>\\d+)_?(?<patch>\\d+)?$",
"matchPackageNames": [
"potiuk/get-workflow-origin"
],
"versioning": "regex:^v(?<major>\\d+)_(?<minor>\\d+)_?(?<patch>\\d+)?$"
},
{
"matchPackagePatterns": [
"*"
],
"matchDatasources": [
"docker"
],
"groupName": "container images"
},
{
"matchPackagePatterns": [
"*"
],
"matchDatasources": [
"go",
"golang-version"
],
"groupName": "go packages"
},
{
"matchPackagePatterns": [
"*"
],
"matchDatasources": [
"npm"
],
"groupName": "node packages"
},
{
"matchPackagePatterns": [
"*"
],
"matchDatasources": [
"git-refs",
"git-tags",
"github-tags",
"github-releases"
],
"groupName": "releases"
]
}
]
],
"separateMajorMinor": false
}
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-11-14T12:41:15Z by kres 192a4d9c.
# Generated on 2024-12-16T12:49:58Z by kres 8183c20-dirty.

# options for analysis running
run:
Expand Down Expand Up @@ -148,6 +148,7 @@ linters:
- perfsprint # complains about us using fmt.Sprintf in non-performance critical code, updating just kres took too long
- goimports # same as gci
- musttag # seems to be broken - goes into imported libraries and reports issues there
- exportloopref # WARN The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar.

issues:
exclude: [ ]
Expand Down
21 changes: 21 additions & 0 deletions .kres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,24 @@ spec:
deny:
- pkg: io/ioutil
desc: Test rule 2
---
kind: common.Renovate
spec:
customManagers:
- customType: regex
fileMatch:
- internal/config/constants.go
matchStrings:
- '\/\/\s+renovate: datasource=(?<datasource>.*?)(?:\s+extractVersion=(?<extractVersion>.+?))?(?:\s+versioning=(?<versioning>.+?))?\s+depName=(?<depName>.+?)?\s.*Version\s+=\s+\"(?<currentValue>.+?)\"'
versioningTemplate: "{{#if versioning}}{{versioning}}{{else}}semver{{/if}}"
packageRules:
- matchPackageNames:
- actions/checkout
- docker/login-action
- crazy-max/ghaction-github-release
- docker/setup-buildx-action
- slackapi/slack-github-action
versioning: "regex:^v(?<major>\\d+)"
- matchPackageNames:
- potiuk/get-workflow-origin
versioning: "regex:^v(?<major>\\d+)_(?<minor>\\d+)_?(?<patch>\\d+)?$"
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-12-06T11:22:01Z by kres c401487d.
# Generated on 2024-12-16T13:00:41Z by kres fb2c01d-dirty.

ARG TOOLCHAIN

Expand All @@ -13,10 +13,10 @@ FROM ghcr.io/siderolabs/fhs:v1.9.0 AS image-fhs
# runs markdownlint
FROM docker.io/oven/bun:1.1.38-alpine AS lint-markdown
WORKDIR /src
RUN bun i [email protected] sentences-per-line@0.2.1
RUN bun i [email protected] sentences-per-line@0.3.0
COPY .markdownlint.json .
COPY ./README.md ./README.md
RUN bunx markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules node_modules/sentences-per-line/index.js .
RUN bunx markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules sentences-per-line .

# base toolchain image
FROM --platform=${BUILDPLATFORM} ${TOOLCHAIN} AS toolchain
Expand Down
2 changes: 2 additions & 0 deletions cmd/kres/cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/siderolabs/kres/internal/output/makefile"
"github.com/siderolabs/kres/internal/output/markdownlint"
"github.com/siderolabs/kres/internal/output/release"
"github.com/siderolabs/kres/internal/output/renovate"
"github.com/siderolabs/kres/internal/output/sops"
"github.com/siderolabs/kres/internal/output/template"
"github.com/siderolabs/kres/internal/project/auto"
Expand Down Expand Up @@ -74,6 +75,7 @@ func runGen() error {
outputs := []output.Writer{
output.Wrap[github.Compiler](github.NewOutput()),
output.Wrap[sops.Compiler](sops.NewOutput()),
output.Wrap[renovate.Compiler](renovate.NewOutput()),
output.Wrap[conform.Compiler](conform.NewOutput()),
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.23.4
require (
github.com/drone/drone-yaml v1.2.3
github.com/go-git/go-git/v5 v5.12.0
github.com/google/go-github/v66 v66.0.0
github.com/google/go-github/v67 v67.0.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/siderolabs/gen v0.7.0
github.com/spf13/cobra v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v66 v66.0.0 h1:ADJsaXj9UotwdgK8/iFZtv7MLc8E8WBl62WLd/D/9+M=
github.com/google/go-github/v66 v66.0.0/go.mod h1:+4SO9Zkuyf8ytMj0csN1NR/5OTR+MfqPp8P8dVlcvY4=
github.com/google/go-github/v67 v67.0.0 h1:g11NDAmfaBaCO8qYdI9fsmbaRipHNWRIU/2YGvlh4rg=
github.com/google/go-github/v67 v67.0.0/go.mod h1:zH3K7BxjFndr9QSeFibx4lTKkYS3K9nDanoI1NjaOtY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
Expand Down
4 changes: 2 additions & 2 deletions internal/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
DeepCopyVersion = "v0.5.6"
// DindContainerImageVersion is the version of the dind container image.
// renovate: datasource=docker versioning=docker depName=docker
DindContainerImageVersion = "27.3-dind"
DindContainerImageVersion = "27.4-dind"
// DockerfileFrontendImageVersion is the version of the dockerfile frontend image.
// renovate: datasource=docker versioning=docker depName=docker/dockerfile-upstream
DockerfileFrontendImageVersion = "1.12.0-labs"
Expand Down Expand Up @@ -87,7 +87,7 @@ const (
ReleaseActionVersion = "v2"
// SentencesPerLineVersion is the version of sentences-per-line.
// renovate: datasource=npm depName=sentences-per-line
SentencesPerLineVersion = "0.2.1"
SentencesPerLineVersion = "0.3.0"
// SetupBuildxActionVersion is the version of setup-buildx github action.
// renovate: datasource=github-releases extractVersion=^(?<version>v\d+)\.\d+\.\d+$ depName=docker/setup-buildx-action
SetupBuildxActionVersion = "v3"
Expand Down
2 changes: 1 addition & 1 deletion internal/output/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"fmt"
"os"

"github.com/google/go-github/v66/github"
"github.com/google/go-github/v67/github"
"golang.org/x/oauth2"
)

Expand Down
1 change: 1 addition & 0 deletions internal/output/golangci/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ linters:
- perfsprint # complains about us using fmt.Sprintf in non-performance critical code, updating just kres took too long
- goimports # same as gci
- musttag # seems to be broken - goes into imported libraries and reports issues there
- exportloopref # WARN The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar.

issues:
exclude: [ ]
Expand Down
121 changes: 121 additions & 0 deletions internal/output/renovate/renovate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

// Package renovate implements output to .github/renovate.json
package renovate

import (
"encoding/json"
"fmt"
"io"
"slices"

"github.com/siderolabs/kres/internal/output"
)

// Output provides output to .github/renovate.json.
type Output struct {
output.FileAdapter

result *Renovate

enabled bool
}

const (
fileName = ".github/renovate.json"
)

// NewOutput initializes Output.
func NewOutput() *Output {
o := &Output{}

o.FileWriter = o

preamble := output.Preamble("")

o.result = &Renovate{
Schema: "https://docs.renovatebot.com/renovate-schema.json",
Description: preamble,
Extends: []string{
":dependencyDashboard",
":gitSignOff",
":semanticCommitScopeDisabled",
"schedule:earlyMondays",
},
PRHeader: "Update Request | Renovate Bot",
SeparateMajorMinor: false,
PackageRules: []PackageRule{
{
MatchUpdateTypes: []string{
"major",
"minor",
"patch",
"pin",
"digest",
},
GroupName: "dependencies",
},
},
}

return o
}

// Compile implements [output.TypedWriter] interface.
func (o *Output) Compile(compiler Compiler) error {
return compiler.CompileRenovate(o)
}

// Enable should be called to enable config generation.
func (o *Output) Enable() {
o.enabled = true
}

// CustomManagers sets custom managers.
func (o *Output) CustomManagers(customManagers []CustomManager) {
o.result.CustomManagers = customManagers
}

// PackageRules sets package rules.
func (o *Output) PackageRules(packageRules []PackageRule) {
o.result.PackageRules = slices.Concat(o.result.PackageRules, packageRules)
}

// Filenames implements output.FileWriter interface.
func (o *Output) Filenames() []string {
if !o.enabled {
return nil
}

return []string{fileName}
}

// GenerateFile implements output.FileWriter interface.
func (o *Output) GenerateFile(filename string, w io.Writer) error {
switch filename {
case fileName:
return o.renovate(w)
default:
panic("unexpected filename: " + fileName)
}
}

func (o *Output) renovate(w io.Writer) error {
encoder := json.NewEncoder(w)

encoder.SetIndent("", " ")
encoder.SetEscapeHTML(false)

if err := encoder.Encode(o.result); err != nil {
return fmt.Errorf("failed to encode renovate config: %w", err)
}

return nil
}

// Compiler is implemented by project blocks which support renovate config generation.
type Compiler interface {
CompileRenovate(*Output) error
}
33 changes: 33 additions & 0 deletions internal/output/renovate/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package renovate

// Renovate represents the renovate configuration.
type Renovate struct {
Schema string `json:"$schema"`
Description string `json:"description"`
PRHeader string `json:"prHeader"`
Extends []string `json:"extends"`
CustomManagers []CustomManager `json:"customManagers,omitempty"`
PackageRules []PackageRule `json:"packageRules,omitempty"`
SeparateMajorMinor bool `json:"separateMajorMinor"`
}

// CustomManager represents a custom manager.
type CustomManager struct {
CustomType string `json:"customType"`
VersioningTemplate string `json:"versioningTemplate"`
FileMatch []string `json:"fileMatch"`
MatchStrings []string `json:"matchStrings"`
}

// PackageRule represents a package rule.
type PackageRule struct {
GroupName string `json:"groupName,omitempty"`
Versioning string `json:"versioning,omitempty"`

MatchPackageNames []string `json:"matchPackageNames,omitempty"`
MatchUpdateTypes []string `json:"matchUpdateTypes,omitempty"`
}
Loading

0 comments on commit 071772c

Please sign in to comment.