From 8514537d551f78cc81c556c38d158b849ff2e008 Mon Sep 17 00:00:00 2001 From: sapcc-bot Date: Thu, 28 Nov 2024 17:31:50 +0000 Subject: [PATCH] Run go-makefile-maker --- Makefile | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index eee68c75..72d23a11 100644 --- a/Makefile +++ b/Makefile @@ -14,11 +14,17 @@ endif default: build-all -prepare-static-check: FORCE +install-golangci-lint: FORCE @if ! hash golangci-lint 2>/dev/null; then printf "\e[1;36m>> Installing golangci-lint (this may take a while)...\e[0m\n"; go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; fi + +install-go-licence-detector: FORCE @if ! hash go-licence-detector 2>/dev/null; then printf "\e[1;36m>> Installing go-licence-detector...\e[0m\n"; go install go.elastic.co/go-licence-detector@latest; fi + +install-addlicense: FORCE @if ! hash addlicense 2>/dev/null; then printf "\e[1;36m>> Installing addlicense...\e[0m\n"; go install github.com/google/addlicense@latest; fi +prepare-static-check: FORCE install-golangci-lint install-go-licence-detector install-addlicense + install-controller-gen: FORCE @if ! hash controller-gen 2>/dev/null; then printf "\e[1;36m>> Installing controller-gen...\e[0m\n"; go install sigs.k8s.io/controller-tools/cmd/controller-gen@latest; fi @@ -75,7 +81,7 @@ generate: install-controller-gen @controller-gen crd rbac:roleName=absent-metrics-operator webhook paths="./..." output:crd:artifacts:config=crd @controller-gen object paths="./..." -run-golangci-lint: FORCE prepare-static-check +run-golangci-lint: FORCE install-golangci-lint @printf "\e[1;36m>> golangci-lint\e[0m\n" @golangci-lint run @@ -103,15 +109,19 @@ vendor-compat: FORCE go mod vendor go mod verify -license-headers: FORCE prepare-static-check +force-license-headers: FORCE install-addlicense + @printf "\e[1;36m>> addlicense\e[0m\n" + echo -n $(patsubst $(shell awk '$$1 == "module" {print $$2}' go.mod)%,.%/*.go,$(shell go list ./...)) | xargs -d" " -I{} bash -c 'year="$$(rg -P "Copyright (....) SAP SE" -Nor "\$$1" {})"; awk -i inplace '"'"'{if (display) {print} else {!/^\/\*/ && !/^\*/ && !/^\$$/}}; /^package /{print;display=1}'"'"' {}; addlicense -c "SAP SE" -s -y "$$year" -- {}' + +license-headers: FORCE install-addlicense @printf "\e[1;36m>> addlicense\e[0m\n" - @addlicense -c "SAP SE" -- $(patsubst $(shell awk '$$1 == "module" {print $$2}' go.mod)%,.%/*.go,$(shell go list ./...)) + @addlicense -c "SAP SE" -s -- $(patsubst $(shell awk '$$1 == "module" {print $$2}' go.mod)%,.%/*.go,$(shell go list ./...)) -check-license-headers: FORCE prepare-static-check +check-license-headers: FORCE install-addlicense @printf "\e[1;36m>> addlicense --check\e[0m\n" @addlicense --check -- $(patsubst $(shell awk '$$1 == "module" {print $$2}' go.mod)%,.%/*.go,$(shell go list ./...)) -check-dependency-licenses: FORCE prepare-static-check +check-dependency-licenses: FORCE install go-licence-detector @printf "\e[1;36m>> go-licence-detector\e[0m\n" @go list -m -mod=readonly -json all | go-licence-detector -includeIndirect -rules .license-scan-rules.json -overrides .license-scan-overrides.jsonl @@ -139,6 +149,9 @@ help: FORCE @printf " \e[36mhelp\e[0m Display this help.\n" @printf "\n" @printf "\e[1mPrepare\e[0m\n" + @printf " \e[36minstall-golangci-lint\e[0m Install golangci-lint required by run-golangci-lint/static-check\n" + @printf " \e[36minstall-go-licence-detector\e[0m Install go-licence-detector required by check-dependency-licenses/static-check\n" + @printf " \e[36minstall-addlicense\e[0m Install addlicense required by check-license-headers/license-headers/static-check\n" @printf " \e[36mprepare-static-check\e[0m Install any tools required by static-check. This is used in CI before dropping privileges, you should probably install all the tools using your package manager\n" @printf " \e[36minstall-controller-gen\e[0m Install controller-gen required by static-check and build-all. This is used in CI before dropping privileges, you should probably install all the tools using your package manager\n" @printf " \e[36minstall-setup-envtest\e[0m Install setup-envtest required by check. This is used in CI before dropping privileges, you should probably install all the tools using your package manager\n" @@ -160,6 +173,7 @@ help: FORCE @printf "\e[1mDevelopment\e[0m\n" @printf " \e[36mvendor\e[0m Run go mod tidy, go mod verify, and go mod vendor.\n" @printf " \e[36mvendor-compat\e[0m Same as 'make vendor' but go mod tidy will use '-compat' flag with the Go version from go.mod file as value.\n" + @printf " \e[36mforce-license-headers\e[0m Remove and re-add all license headers to all non-vendored source code files.\n" @printf " \e[36mlicense-headers\e[0m Add license headers to all non-vendored source code files.\n" @printf " \e[36mcheck-license-headers\e[0m Check license headers in all non-vendored .go files.\n" @printf " \e[36mcheck-dependency-licenses\e[0m Check all dependency licenses using go-licence-detector.\n"