Skip to content

Commit 86b6474

Browse files
Document license and make license-headers configurable
1 parent 23e908b commit 86b6474

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ The config file has the following sections:
7575
* [golang](#golang)
7676
* [golangciLint](#golangcilint)
7777
* [goReleaser](#goreleaser)
78+
* [license](#license)
7879
* [makefile](#makefile)
7980
* [metadata](#metadata)
8081
* [nix](#nix)
@@ -289,6 +290,28 @@ The `nameTemplate` option can be used to change the name of uploaded release art
289290

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

293+
### `license`
294+
295+
```yaml
296+
license:
297+
addHeaders: true
298+
checkDependencies: true
299+
copyright: 'SAP SE or an SAP affiliate company'
300+
spdx: Apache-2.0
301+
```
302+
303+
`license` contains settings related to the license of the project and specifically license header generation.
304+
305+
`addHeaders` controls whether license headers are added and checked in source files.
306+
307+
`checkDependencies` controls whether dependency licenses are checked for compliance.
308+
309+
`copyright` is the text to be used in the copyright line of the license header.
310+
311+
`spdx` is the SPDX short identifier of the license to be used in the license header.
312+
313+
In SAP Cloud Infrastructure projects all checks are enabled by default and the copyright and SPDX identifier are prefilled accordingly.
314+
292315
### `makefile`
293316

294317
```yaml

internal/core/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ type ControllerGen struct {
255255
}
256256

257257
type LicenseConfig struct {
258-
Copyright Option[string] `yaml:"copyright"`
258+
AddHeaders Option[bool] `yaml:"addHeaders"`
259+
CheckDependencies Option[bool] `yaml:"checkDependencies"`
260+
Copyright Option[string] `yaml:"copyright"`
261+
SPDX Option[string] `yaml:"spdx"`
259262
}
260263

261264
type MakefileConfig struct {

internal/makefile/makefile.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ endif
135135
prepareStaticRecipe = append(prepareStaticRecipe, "install-shellcheck")
136136
}
137137

138-
if isSAPCC {
139-
if isGolang {
140-
prepare.addRule(rule{
141-
description: "Install-go-licence-detector required by check-dependency-licenses/static-check",
142-
phony: true,
143-
target: "install-go-licence-detector",
144-
recipe: installTool("go-licence-detector", "go.elastic.co/go-licence-detector@latest"),
145-
})
146-
prepareStaticRecipe = append(prepareStaticRecipe, "install-go-licence-detector")
147-
}
138+
if isGolang && (cfg.License.AddHeaders.UnwrapOr(isSAPCC) || cfg.License.CheckDependencies.UnwrapOr(isSAPCC)) {
139+
prepare.addRule(rule{
140+
description: "Install-go-licence-detector required by check-dependency-licenses/static-check",
141+
phony: true,
142+
target: "install-go-licence-detector",
143+
recipe: installTool("go-licence-detector", "go.elastic.co/go-licence-detector@latest"),
144+
})
145+
prepareStaticRecipe = append(prepareStaticRecipe, "install-go-licence-detector")
146+
}
147+
if cfg.License.AddHeaders.UnwrapOr(isSAPCC) {
148148
prepare.addRule(rule{
149149
description: "Install addlicense required by check-license-headers/license-headers/static-check",
150150
phony: true,
@@ -490,7 +490,7 @@ endif
490490
allSourceFilesExpr = `$(shell find -name *.rs)`
491491
}
492492

493-
if isSAPCC {
493+
if cfg.License.AddHeaders.UnwrapOr(isSAPCC) {
494494
var ignoreOptions []string
495495
if cfg.GitHubWorkflow != nil {
496496
for _, pattern := range cfg.GitHubWorkflow.License.IgnorePatterns {
@@ -592,11 +592,16 @@ endif
592592
}
593593
}
594594

595+
staticCheckPrerequisites := []string{"run-shellcheck"}
596+
595597
if isGolang {
596598
// add target for static code checks
597-
staticCheckPrerequisites := []string{"run-shellcheck", "run-golangci-lint", "run-modernize"}
598-
if isSAPCC {
599-
staticCheckPrerequisites = append(staticCheckPrerequisites, "check-dependency-licenses", "check-license-headers")
599+
staticCheckPrerequisites = append(staticCheckPrerequisites, "run-golangci-lint", "run-modernize")
600+
if cfg.License.CheckDependencies.UnwrapOr(isSAPCC) {
601+
staticCheckPrerequisites = append(staticCheckPrerequisites, "check-dependency-licenses")
602+
}
603+
if cfg.License.AddHeaders.UnwrapOr(isSAPCC) {
604+
staticCheckPrerequisites = append(staticCheckPrerequisites, "check-license-headers")
600605
}
601606
test.addRule(rule{
602607
description: "Run static code checks (internal option to enforce --keep-going)",

0 commit comments

Comments
 (0)