diff --git a/.github/renovate.json b/.github/renovate.json index 25a1e034..75ed3174 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -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=(?.*?)(?:\\s+extractVersion=(?.+?))?(?:\\s+versioning=(?.+?))?\\s+depName=(?.+?)?\\s.*Version\\s+=\\s+\\\"(?.+?)\\\"" - ], - "versioningTemplate": "{{#if versioning}}{{versioning}}{{else}}semver{{/if}}" + ] } ], "packageRules": [ { - "matchPackageNames": [ - "golang/go" - ], - "versioning": "regex:^(?\\d+)\\.(?\\d+)\\.?(?\\d+)?$" + "groupName": "dependencies", + "matchUpdateTypes": [ + "major", + "minor", + "patch", + "pin", + "digest" + ] }, { + "versioning": "regex:^v(?\\d+)", "matchPackageNames": [ "actions/checkout", "docker/login-action", "crazy-max/ghaction-github-release", "docker/setup-buildx-action", "slackapi/slack-github-action" - ], - "versioning": "regex:^v(?\\d+)" + ] }, { + "versioning": "regex:^v(?\\d+)_(?\\d+)_?(?\\d+)?$", "matchPackageNames": [ "potiuk/get-workflow-origin" - ], - "versioning": "regex:^v(?\\d+)_(?\\d+)_?(?\\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 } diff --git a/.golangci.yml b/.golangci.yml index d0df7996..5b6a0fbb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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: @@ -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: [ ] diff --git a/.kres.yaml b/.kres.yaml index 1b32de83..1109841c 100644 --- a/.kres.yaml +++ b/.kres.yaml @@ -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=(?.*?)(?:\s+extractVersion=(?.+?))?(?:\s+versioning=(?.+?))?\s+depName=(?.+?)?\s.*Version\s+=\s+\"(?.+?)\"' + 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(?\\d+)" + - matchPackageNames: + - potiuk/get-workflow-origin + versioning: "regex:^v(?\\d+)_(?\\d+)_?(?\\d+)?$" diff --git a/Dockerfile b/Dockerfile index 030c7eb4..8cb7bc57 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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 markdownlint-cli@0.43.0 sentences-per-line@0.2.1 +RUN bun i markdownlint-cli@0.43.0 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 diff --git a/cmd/kres/cmd/gen.go b/cmd/kres/cmd/gen.go index b0ce6bc3..4b4df861 100644 --- a/cmd/kres/cmd/gen.go +++ b/cmd/kres/cmd/gen.go @@ -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" @@ -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()), } diff --git a/go.mod b/go.mod index 3b05a659..b614fed5 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index d995d53b..003f2323 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/config/constants.go b/internal/config/constants.go index d36b2696..ee07f675 100644 --- a/internal/config/constants.go +++ b/internal/config/constants.go @@ -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" @@ -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=^(?v\d+)\.\d+\.\d+$ depName=docker/setup-buildx-action SetupBuildxActionVersion = "v3" diff --git a/internal/output/github/github.go b/internal/output/github/github.go index 27c9239a..86647e7c 100644 --- a/internal/output/github/github.go +++ b/internal/output/github/github.go @@ -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" ) diff --git a/internal/output/golangci/golangci.yml b/internal/output/golangci/golangci.yml index 4abdeca6..92f6c4e7 100644 --- a/internal/output/golangci/golangci.yml +++ b/internal/output/golangci/golangci.yml @@ -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: [ ] diff --git a/internal/output/renovate/renovate.go b/internal/output/renovate/renovate.go new file mode 100644 index 00000000..7a1c124c --- /dev/null +++ b/internal/output/renovate/renovate.go @@ -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 +} diff --git a/internal/output/renovate/types.go b/internal/output/renovate/types.go new file mode 100644 index 00000000..86610b11 --- /dev/null +++ b/internal/output/renovate/types.go @@ -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"` +} diff --git a/internal/project/auto/builder.go b/internal/project/auto/builder.go index 2aa12fc8..484edee8 100644 --- a/internal/project/auto/builder.go +++ b/internal/project/auto/builder.go @@ -130,11 +130,12 @@ func (builder *builder) build() error { makeHelp := common.NewMakeHelp(builder.meta) conformance := common.NewConformance(builder.meta) sops := common.NewSOPS(builder.meta) + renovate := common.NewRenovate(builder.meta) release.AddInput(builder.targets...) builder.proj.AddTarget(builder.targets...) - builder.proj.AddTarget(rekres, all, makeHelp, release, conformance, sops) + builder.proj.AddTarget(rekres, all, makeHelp, release, conformance, sops, renovate) return nil } diff --git a/internal/project/auto/ci.go b/internal/project/auto/ci.go index b455709b..f2382899 100644 --- a/internal/project/auto/ci.go +++ b/internal/project/auto/ci.go @@ -46,6 +46,7 @@ func (builder *builder) BuildCI() error { if builder.meta.CompileGithubWorkflowsOnly { targets = append(targets, common.NewRepository(builder.meta)) targets = append(targets, common.NewSOPS(builder.meta)) + targets = append(targets, common.NewRenovate(builder.meta)) } builder.proj.AddTarget(targets...) diff --git a/internal/project/common/renovate.go b/internal/project/common/renovate.go new file mode 100644 index 00000000..5c5200ab --- /dev/null +++ b/internal/project/common/renovate.go @@ -0,0 +1,74 @@ +// 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 common + +import ( + "github.com/siderolabs/gen/xslices" + + "github.com/siderolabs/kres/internal/dag" + "github.com/siderolabs/kres/internal/output/renovate" + "github.com/siderolabs/kres/internal/project/meta" +) + +// Renovate is a node that represents the renovate configuration. +type Renovate struct { + dag.BaseNode + + meta *meta.Options + + CustomManagers []CustomManager `yaml:"customManagers,omitempty"` + PackageRules []PackageRule `yaml:"packageRules,omitempty"` + Enabled bool `yaml:"enabled"` +} + +// CustomManager represents a custom manager. +type CustomManager struct { + VersioningTemplate string `yaml:"versioningTemplate"` + CustomType string `yaml:"customType"` + FileMatch []string `yaml:"fileMatch"` + MatchStrings []string `yaml:"matchStrings"` +} + +// PackageRule represents a package rule. +type PackageRule struct { + Versioning string `yaml:"versioning,omitempty"` + MatchPackageNames []string `yaml:"matchPackageNames,omitempty"` +} + +// NewRenovate creates a new Renovate node. +func NewRenovate(meta *meta.Options) *Renovate { + return &Renovate{ + BaseNode: dag.NewBaseNode("renovate"), + + meta: meta, + + Enabled: true, + } +} + +// CompileRenovate implements renovate.Compiler. +func (r *Renovate) CompileRenovate(o *renovate.Output) error { + if !r.Enabled { + return nil + } + + o.Enable() + o.CustomManagers(xslices.Map(r.CustomManagers, func(cm CustomManager) renovate.CustomManager { + return renovate.CustomManager{ + CustomType: cm.CustomType, + FileMatch: cm.FileMatch, + MatchStrings: cm.MatchStrings, + VersioningTemplate: cm.VersioningTemplate, + } + })) + o.PackageRules(xslices.Map(r.PackageRules, func(pr PackageRule) renovate.PackageRule { + return renovate.PackageRule{ + MatchPackageNames: pr.MatchPackageNames, + Versioning: pr.Versioning, + } + })) + + return nil +} diff --git a/internal/project/common/repository.go b/internal/project/common/repository.go index 5ea22d42..67897871 100644 --- a/internal/project/common/repository.go +++ b/internal/project/common/repository.go @@ -10,7 +10,7 @@ import ( "net/http" "slices" - "github.com/google/go-github/v66/github" + "github.com/google/go-github/v67/github" "github.com/siderolabs/gen/xslices" "github.com/siderolabs/kres/internal/config" diff --git a/internal/project/markdown/lint.go b/internal/project/markdown/lint.go index d7ac3894..37a01153 100644 --- a/internal/project/markdown/lint.go +++ b/internal/project/markdown/lint.go @@ -57,7 +57,7 @@ func (lint *Lint) CompileDockerfile(output *dockerfile.Output) error { } stage. - Step(step.Script(`bunx markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules node_modules/sentences-per-line/index.js .`)) + Step(step.Script(`bunx markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules sentences-per-line .`)) return nil }