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
80 changes: 51 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ The config file has the following sections:
* [golang](#golang)
* [golangciLint](#golangcilint)
* [goReleaser](#goreleaser)
* [license](#license)
* [makefile](#makefile)
* [metadata](#metadata)
* [nix](#nix)
Expand Down Expand Up @@ -289,6 +290,28 @@ The `nameTemplate` option can be used to change the name of uploaded release art

The `files` option can be used to add extra files. For backwards compatibility it defaults to `[ CHANGELOG.md, LICENSE, README.md ]`.

### `license`

```yaml
license:
addHeaders: true
checkDependencies: true
copyright: 'SAP SE or an SAP affiliate company'
spdx: Apache-2.0
```

`license` contains settings related to the license of the project and specifically license header generation.

`addHeaders` controls whether license headers are added and checked in source files.

`checkDependencies` controls whether dependency licenses are checked for compliance.

`copyright` is the text to be used in the copyright line of the license header.

`spdx` is the SPDX short identifier of the license to be used in the license header.

In SAP Cloud Infrastructure projects all checks are enabled by default and the copyright and SPDX identifier are prefilled accordingly.

### `makefile`

```yaml
Expand Down Expand Up @@ -402,7 +425,7 @@ customManagers:

```yaml
reuse:
enabled: false
enabled: true
annotations:
- paths:
- internal/**/fixtures/*.json
Expand Down Expand Up @@ -574,26 +597,23 @@ This workflow:
* checks your code using `golangci-lint`
* ensures that your code compiles successfully
* runs tests and generates test coverage report
* uploads the test coverage report to [Coveralls]

```yaml
ci:
enabled: true
runOn:
- macos-latest
- ubuntu-latest
- windows-latest
coveralls: true
prepareMakeTarget: generate
ignorePaths: []
githubWorkflow:
ci:
enabled: true
runOn:
- macos-latest
- ubuntu-latest
- windows-latest
prepareMakeTarget: generate
ignorePaths: []
```

`runOn` specifies a list of machine(s) to run the `build` and `test` jobs on ([more info][ref-runs-on]).
You can use this to ensure that your build compilation and tests are
successful on multiple operating systems. Default value for this is `ubuntu-latest`.

If `coveralls` is `true` then your test coverage report will be uploaded to [Coveralls]. Make sure that you have enabled Coveralls for your GitHub repo beforehand.

`ignorePaths` specifies a list of filename patterns. Workflows will not trigger if a path
name matches a pattern in this list. [More info][ref-onpushpull] and [filter pattern cheat
sheet][ref-pattern-cheat-sheet]. This option is not defined by default.
Expand All @@ -610,14 +630,15 @@ This is intended for use with `github.com/sapcc/go-bits/easypg`, which can launc
If `enabled` is set to true, the generated `Dockerfile` is built for the platforms `linux/amd64` and `linux/arm64` and pushed to the repository path under `ghcr.io`.

```yaml
pushContainerToGhcr:
enabled: true
platforms: "linux/amd64,linux/arm64"
tagStrategy:
- edge
- latest
- semver
- sha
githubWorkflow:
pushContainerToGhcr:
enabled: true
platforms: "linux/amd64,linux/arm64"
tagStrategy:
- edge
- latest
- semver
- sha
```

`platforms` configures for which platforms the multi-arch docker image is built. Defaults to `linux/amd64`. Note: emulation is provided by qemu and might take significant time.
Expand Down Expand Up @@ -650,9 +671,10 @@ If `securityChecks` is enabled then it will generate the following workflows:
It uses the [Go Vulnerability Database](https://pkg.go.dev/vuln/) as a source.

```yaml
securityChecks:
enabled: true
queries: security-extended
githubWorkflow:
securityChecks:
enabled: true
queries: security-extended
```

`queries` is passed through to the GitHub Action. See the [GitHub Documentation](https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning#working-with-custom-configuration-files) for more information.
Expand All @@ -663,10 +685,11 @@ This workflow uses [`addlicense`][addlicense] to ensure that all your Go source
If vendoring is enabled, the `vendor/` directory is always entirely ignored by this workflow.

```yaml
license:
enabled: true
ignorePatterns:
- "vendor/**"
githubWorkflow:
license:
enabled: true
ignorePatterns:
- "vendor/**"
```

`ignorePatterns` specifies a list of file patterns to check. You can use any pattern
Expand All @@ -675,7 +698,6 @@ license:
**Hint**: You can also use `addlicense` to add license headers to all unignored Go files by running `make license-headers`. The copyright text used is customizable by setting `license.copyright` in the `Makefile.maker.yaml` file.

[codeql]: https://codeql.github.com/
[coveralls]: https://coveralls.io
[doublestar-pattern]: https://github.com/bmatcuk/doublestar#patterns
[go-licence-detector]: https://github.com/elastic/go-licence-detector
[govulncheck]: https://github.com/golang/vuln
Expand Down
7 changes: 5 additions & 2 deletions internal/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ type GithubWorkflowConfiguration struct {
// CIWorkflowConfig appears in type Configuration.
type CIWorkflowConfig struct {
Enabled bool `yaml:"enabled"`
Coveralls bool `yaml:"coveralls"`
PrepareMakeTarget string `yaml:"prepareMakeTarget"`
IgnorePaths []string `yaml:"ignorePaths"`
RunsOn []string `yaml:"runOn"`
Expand Down Expand Up @@ -256,7 +255,10 @@ type ControllerGen struct {
}

type LicenseConfig struct {
Copyright Option[string] `yaml:"copyright"`
AddHeaders Option[bool] `yaml:"addHeaders"`
CheckDependencies Option[bool] `yaml:"checkDependencies"`
Copyright Option[string] `yaml:"copyright"`
SPDX Option[string] `yaml:"spdx"`
}

type MakefileConfig struct {
Expand All @@ -273,6 +275,7 @@ func (m Metadata) IsSAPProject() bool {
return strings.HasPrefix(m.URL, "https://github.com/sapcc/") ||
strings.HasPrefix(m.URL, "https://github.com/SAP-cloud-infrastructure/") ||
strings.HasPrefix(m.URL, "https://github.com/cobaltcore-dev/") ||
strings.HasPrefix(m.URL, "https://github.com/cloudoperators/") ||
strings.HasPrefix(m.URL, "https://github.com/ironcore-dev/") ||
strings.HasPrefix(m.URL, "https://github.wdf.sap.corp/") ||
strings.HasPrefix(m.URL, "https://github.tools.sap/")
Expand Down
66 changes: 39 additions & 27 deletions internal/makefile/makefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func newMakefile(cfg core.Configuration, sr golang.ScanResult) *makefile {
runControllerGen := cfg.ControllerGen.Enabled.UnwrapOr(sr.KubernetesController)
// TODO: checking on GoVersion is only an aid until we can properly detect rust applications
isGolang := sr.GoVersion != ""

if !strings.HasPrefix(cfg.Metadata.URL, "https://") {
logg.Error("The option metadata.url should always start with https://, eg: https://github.com/sapcc/go-makefile-maker")
logg.Error("Some defaults or usages of the metadata might not work correctly")
}

isSAPCC := cfg.Metadata.IsSAPProject()

///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -135,16 +141,16 @@ endif
prepareStaticRecipe = append(prepareStaticRecipe, "install-shellcheck")
}

if isSAPCC {
if isGolang {
prepare.addRule(rule{
description: "Install-go-licence-detector required by check-dependency-licenses/static-check",
phony: true,
target: "install-go-licence-detector",
recipe: installTool("go-licence-detector", "go.elastic.co/go-licence-detector@latest"),
})
prepareStaticRecipe = append(prepareStaticRecipe, "install-go-licence-detector")
}
if isGolang && (cfg.License.AddHeaders.UnwrapOr(isSAPCC) || cfg.License.CheckDependencies.UnwrapOr(isSAPCC)) {
prepare.addRule(rule{
description: "Install-go-licence-detector required by check-dependency-licenses/static-check",
phony: true,
target: "install-go-licence-detector",
recipe: installTool("go-licence-detector", "go.elastic.co/go-licence-detector@latest"),
})
prepareStaticRecipe = append(prepareStaticRecipe, "install-go-licence-detector")
}
if cfg.License.AddHeaders.UnwrapOr(isSAPCC) {
prepare.addRule(rule{
description: "Install addlicense required by check-license-headers/license-headers/static-check",
phony: true,
Expand Down Expand Up @@ -490,7 +496,7 @@ endif
allSourceFilesExpr = `$(shell find -name *.rs)`
}

if isSAPCC {
if cfg.License.AddHeaders.UnwrapOr(isSAPCC) {
var ignoreOptions []string
if cfg.GitHubWorkflow != nil {
for _, pattern := range cfg.GitHubWorkflow.License.IgnorePatterns {
Expand Down Expand Up @@ -592,25 +598,13 @@ endif
}
}

staticCheckPrerequisites := []string{"run-shellcheck"}
if isGolang {
// add target for static code checks
staticCheckPrerequisites := []string{"run-shellcheck", "run-golangci-lint", "run-modernize"}
if isSAPCC {
staticCheckPrerequisites = append(staticCheckPrerequisites, "check-dependency-licenses", "check-license-headers")
staticCheckPrerequisites = append(staticCheckPrerequisites, "run-golangci-lint", "run-modernize")
if cfg.License.CheckDependencies.UnwrapOr(isSAPCC) {
staticCheckPrerequisites = append(staticCheckPrerequisites, "check-dependency-licenses")
}
test.addRule(rule{
description: "Run static code checks (internal option to enforce --keep-going)",
phony: true,
target: "__static-check",
hideTarget: true,
prerequisites: staticCheckPrerequisites,
})
test.addRule(rule{
description: "Run static code checks",
phony: true,
target: "static-check",
recipe: []string{`@$(MAKE) --keep-going --no-print-directory __static-check`},
})

dev.addRule(rule{
description: "Run goimports on all non-vendored .go files",
Expand All @@ -635,6 +629,24 @@ endif
})
}

if cfg.License.AddHeaders.UnwrapOr(isSAPCC) {
staticCheckPrerequisites = append(staticCheckPrerequisites, "check-license-headers")
}

test.addRule(rule{
description: "Run static code checks (internal option to enforce --keep-going)",
phony: true,
target: "__static-check",
hideTarget: true,
prerequisites: staticCheckPrerequisites,
})
test.addRule(rule{
description: "Run static code checks",
phony: true,
target: "static-check",
recipe: []string{`@$(MAKE) --keep-going --no-print-directory __static-check`},
})

// add cleaning target
dev.addRule(rule{
description: "Run git clean.",
Expand Down
6 changes: 2 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func main() {
must.Succeed(file.Close())
cfg.Validate()

if cfg.GitHubWorkflow != nil && !strings.HasPrefix(cfg.Metadata.URL, "https://github.com/") {
// The github.com/ prefix is just a safeguard to avoid false positives when the metadata.url is not complete.
if cfg.GitHubWorkflow != nil && !strings.Contains(cfg.Metadata.URL, "github.com/") {
cfg.GitHubWorkflow.IsSelfHostedRunner = true
if strings.Contains(cfg.Metadata.URL, "/sap-cloud-infrastructure/") {
cfg.GitHubWorkflow.IsSugarRunner = true
Expand Down Expand Up @@ -112,9 +113,6 @@ func main() {
// Render GitHub workflows
if cfg.GitHubWorkflow != nil {
logg.Debug("rendering GitHub Actions workflows")
if cfg.GitHubWorkflow.CI.Coveralls {
logg.Fatal("Coveralls support has been removed, please remove it from your Makefile.maker.yaml")
}
ghworkflow.Render(cfg, sr)
}

Expand Down
Loading