Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ linters:
- perfsprint
- predeclared
- rowserrcheck
- revive
- sqlclosecheck
- staticcheck
- unconvert
Expand Down Expand Up @@ -159,6 +160,12 @@ linters:
perfsprint:
# modernize generates nicer fix code
concat-loop: false
revive:
rules:
- name: exported
arguments:
- checkPrivateReceivers
- disableChecksOnConstants
staticcheck:
dot-import-whitelist:
- github.com/majewsky/gg/option
Expand Down
5 changes: 5 additions & 0 deletions Makefile.maker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ golang:

golangciLint:
createConfig: true
reviveRules:
- name: exported
arguments:
- checkPrivateReceivers
- disableChecksOnConstants

githubWorkflow:
ci:
Expand Down
19 changes: 18 additions & 1 deletion internal/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"github.com/sapcc/go-bits/regexpext"
)

// AutogeneratedHeader is a template.Template which gets used for inserting
// copyright and license information into files.
//
//go:embed autogenerated-header.tmpl
var AutogeneratedHeader string

Expand Down Expand Up @@ -109,6 +112,7 @@ type GolangConfiguration struct {
SetGoModVersion bool `yaml:"setGoModVersion"`
}

// ReviveRule appears in type GolangciLintConfiguration.
type ReviveRule struct {
Name string `yaml:"name"`
Arguments []string `yaml:"arguments"`
Expand All @@ -123,6 +127,7 @@ type GolangciLintConfiguration struct {
ReviveRules []ReviveRule `yaml:"reviveRules"`
}

// GoReleaserConfiguration appears in type Configuration.
type GoReleaserConfiguration struct {
CreateConfig Option[bool] `yaml:"createConfig"`
BinaryName string `yaml:"binaryName"`
Expand All @@ -132,7 +137,7 @@ type GoReleaserConfiguration struct {
NameTemplate string `yaml:"nameTemplate"`
}

// IsEnabled encodes that the default state for the Enabled field is `false`.
// ShouldCreateConfig encodes that the default state for the CreateConfig field is `false`.
func (g GoReleaserConfiguration) ShouldCreateConfig() bool {
return g.CreateConfig.UnwrapOr(false)
}
Expand Down Expand Up @@ -194,12 +199,14 @@ func (l LicenseWorkflowConfig) IsEnabled() bool {
return l.Enabled.UnwrapOr(true)
}

// PushContainerToGhcrConfig appears in type GithubWorkflowConfiguration.
type PushContainerToGhcrConfig struct {
Enabled bool `yaml:"enabled"`
Platforms string `yaml:"platforms"`
TagStrategy []string `yaml:"tagStrategy"`
}

// ReleaseWorkflowConfig appears in type ReleaseWorkflowConfig.
type ReleaseWorkflowConfig struct {
Enabled Option[bool] `yaml:"enabled"`
}
Expand All @@ -222,6 +229,7 @@ type ShellCheckConfiguration struct {
Opts string `yaml:"opts"`
}

// AllIgnorePaths appends the vendor paths to the IgnorePaths when vendoring is enabled.
func (s ShellCheckConfiguration) AllIgnorePaths(g GolangConfiguration) []string {
if g.EnableVendoring {
return append(slices.Clone(s.IgnorePaths), "./vendor/*")
Expand All @@ -234,6 +242,7 @@ func (s ShellCheckConfiguration) IsEnabled() bool {
return s.Enabled.UnwrapOr(true)
}

// PackageRule appears in type Configuration.
type PackageRule struct {
MatchPackageNames []string `yaml:"matchPackageNames" json:"matchPackageNames,omitempty"`
MatchUpdateTypes []string `yaml:"matchUpdateTypes" json:"matchUpdateTypes,omitempty"`
Expand Down Expand Up @@ -274,6 +283,7 @@ type DockerfileConfig struct {
WithLinkerdAwait bool `yaml:"withLinkerdAwait"`
}

// ControllerGen appears in type Configuration.
type ControllerGen struct {
Enabled Option[bool] `yaml:"enabled"`
CrdOutputPath string `yaml:"crdOutputPath"`
Expand All @@ -282,6 +292,7 @@ type ControllerGen struct {
ApplyconfigurationHeaderFile string `yaml:"applyconfigurationHeaderFile"`
}

// LicenseConfig appears in type Configuration.
type LicenseConfig struct {
AddHeaders Option[bool] `yaml:"addHeaders"`
CheckDependencies Option[bool] `yaml:"checkDependencies"`
Expand All @@ -290,14 +301,17 @@ type LicenseConfig struct {
SPDX Option[string] `yaml:"spdx"`
}

// GetCopyright returns the set copyright string or a default.
func (l LicenseConfig) GetCopyright() string {
return l.Copyright.UnwrapOr("SAP SE or an SAP affiliate company")
}

// GetSPDX returns the set spdx string or a default.
func (l LicenseConfig) GetSPDX() string {
return l.SPDX.UnwrapOr("Apache-2.0")
}

// GoLicenseDetectorConfig appears in type LicenseConfig.
type GoLicenseDetectorConfig struct {
Overrides []LicenseDetectorOverride `yaml:"overrides"`
}
Expand All @@ -312,6 +326,7 @@ type LicenseDetectorOverride struct {
LicenceTextOverrideFile string `yaml:"licenceTextOverrideFile" json:"licenceTextOverrideFile,omitzero"`
}

// MakefileConfig appears in type Configuration.
type MakefileConfig struct {
Enabled Option[bool] `yaml:"enabled"` // this is a pointer to bool to treat an absence as true for backwards compatibility
}
Expand All @@ -332,6 +347,7 @@ func (m Metadata) IsSAPProject() bool {
strings.HasPrefix(m.URL, "https://github.tools.sap/")
}

// NixConfig appears in type Configuration.
type NixConfig struct {
ExtraLibraries []string `yaml:"extraLibraries"`
ExtraPackages []string `yaml:"extraPackages"`
Expand All @@ -340,6 +356,7 @@ type NixConfig struct {
///////////////////////////////////////////////////////////////////////////////
// Helper functions

// Validate checks the provided Configuration for integrity.
func (c *Configuration) Validate() {
if len(c.SpellCheck.IgnoreWords) > 0 {
logg.Fatal("SpellCheck/misspell is deprecated, please migrate to typos")
Expand Down
8 changes: 8 additions & 0 deletions internal/core/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ const (
DefaultGitHubComRunsOn = "ubuntu-latest"
)

// DefaultGitHubEnterpriseRunsOn is a map of group names to runner labels for GitHub Enterprise.
var DefaultGitHubEnterpriseRunsOn = map[string]string{
"group": "organization/Default",
}

// SugarRunsOn is an array of Sugar runners.
var SugarRunsOn = []string{"self-hosted"}

// GetUploadArtifactAction works around GitHub not supporting their own stuff
Expand All @@ -27,6 +30,7 @@ func GetUploadArtifactAction(isSelfHostedRunner bool) string {
}
}

// GetCodeqlInitAction returns the right CodeQL init action for the chosen Runner.
// see https://github.com/github/codeql-action/releases
// and https://github.wdf.sap.corp/Security-Testing/codeql-action/releases
func GetCodeqlInitAction(isSelfHostedRunner bool) string {
Expand All @@ -36,13 +40,17 @@ func GetCodeqlInitAction(isSelfHostedRunner bool) string {
return "github/codeql-action/init@v4"
}
}

// GetCodeqlAnalyzeAction returns the right CodeQL analyze action for the chosen Runner.
func GetCodeqlAnalyzeAction(isSelfHostedRunner bool) string {
if isSelfHostedRunner {
return "Security-Testing/codeql-action/analyze@v3"
} else {
return "github/codeql-action/analyze@v4"
}
}

// GetCodeqlAutobuildAction returns the right CodeQL autobild action for the chosen Runner.
func GetCodeqlAutobuildAction(isSelfHostedRunner bool) string {
if isSelfHostedRunner {
return "Security-Testing/codeql-action/autobuild@v3"
Expand Down
1 change: 1 addition & 0 deletions internal/dockerfile/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
dockerignoreTemplate string
)

// RenderConfig writes the docker configuration files from the provided config and scan results.
func RenderConfig(cfg core.Configuration, sr golang.ScanResult) {
// if there is an entrypoint configured use that otherwise fallback to the first binary name
var entrypoint string
Expand Down
2 changes: 1 addition & 1 deletion internal/ghworkflow/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func baseJob(name string, cfg *core.GithubWorkflowConfiguration) job {
var (
runsOn any
envs map[string]string
strategy JobStrategy
strategy jobStrategy
)

if cfg.IsSelfHostedRunner {
Expand Down
5 changes: 3 additions & 2 deletions internal/ghworkflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type workflowDispatch struct {
manualTrigger bool `yaml:"-"`
}

// IsZero defines whether a workflowDispatch is zero (not set).
func (w workflowDispatch) IsZero() bool {
return !w.manualTrigger
}
Expand Down Expand Up @@ -119,7 +120,7 @@ type job struct {

// Strategy creates a build matrix for the job and allows different
// variations to run each job in.
Strategy JobStrategy `yaml:"strategy,omitempty"`
Strategy jobStrategy `yaml:"strategy,omitempty"`

// A map of <service_id> to their configuration(s).
Services map[string]jobService `yaml:"services,omitempty"`
Expand All @@ -130,7 +131,7 @@ type job struct {
Permissions permissions `yaml:"permissions,omitempty"`
}

type JobStrategy struct {
type jobStrategy struct {
Matrix struct {
OS []string `yaml:"os"`
} `yaml:"matrix"`
Expand Down
1 change: 1 addition & 0 deletions internal/golang/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ScanResult struct {

const ModFilename = "go.mod"

// Scan goes through the configuration files in the project to assemble a ScanResult.
func Scan() ScanResult {
// assume this is not a go project if there is no go.mod file
_, err := os.Stat(ModFilename)
Expand Down
1 change: 1 addition & 0 deletions internal/golangcilint/golangci_lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
configTemplate string
)

// RenderConfig writes the golanci-lint configuration files from the provided config and scan results.
func RenderConfig(cfg core.Configuration, sr golang.ScanResult) {
timeout := 3 * time.Minute
if cfg.GolangciLint.Timeout != 0 {
Expand Down
4 changes: 2 additions & 2 deletions internal/goreleaser/goreleaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
package goreleaser

import (
_ "embed"
"net/url"
"strings"

_ "embed"

"github.com/sapcc/go-makefile-maker/internal/core"
"github.com/sapcc/go-makefile-maker/internal/util"

Expand All @@ -24,6 +23,7 @@ var (
goreleaserTemplate string
)

// RenderConfig writes the goreleaser configuration files from the provided config and scan results.
func RenderConfig(cfg core.Configuration) {
if len(cfg.Binaries) < 1 {
logg.Fatal("GoReleaser requires at least 1 binary to be configured in binaries!")
Expand Down
1 change: 1 addition & 0 deletions internal/nix/nix-shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
envrcTemplate string
)

// RenderShell renders the Nix shell.
func RenderShell(cfg core.Configuration, sr golang.ScanResult, renderGoreleaserConfig bool) {
goVersionSlice := strings.Split(core.DefaultGoVersion, ".")
goPackage := fmt.Sprintf("go_%s_%s", goVersionSlice[0], goVersionSlice[1])
Expand Down
1 change: 1 addition & 0 deletions internal/renovate/renovate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type config struct {
SemanticCommits string `json:"semanticCommits,omitempty"`
}

// RenderConfig writes the renovate configuration files from the provided config and scan results.
func RenderConfig(cfg core.Configuration, scanResult golang.ScanResult) {
isGoMakefileMakerRepo := scanResult.ModulePath == "github.com/sapcc/go-makefile-maker"
isInternalRenovate := strings.HasPrefix(cfg.Metadata.URL, "https://github.wdf.sap.corp")
Expand Down
1 change: 1 addition & 0 deletions internal/reuse/reuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
goLicenceDetectorTemplate []byte
)

// RenderConfig writes the reuse configuration files from the provided config and scan results.
func RenderConfig(cfg core.Configuration, sr golang.ScanResult) {
// If disabled, the REUSE.toml file should not be overridden.
// This is useful if the project needs additional information in
Expand Down
1 change: 1 addition & 0 deletions internal/typos/typos.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
typosConfigTemplate string
)

// RenderConfig writes the typos configuration files from the provided config.
func RenderConfig(cfg core.Configuration) {
extendExcludes := []string{"go.mod"}
if cfg.Golang.EnableVendoring {
Expand Down