diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e593a027c..0b80d2026 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -26,8 +26,6 @@ jobs: - name: Lint run: make lint - env: - KUSTOMIZE_DOCKER_E2E: false # don't need to do e2e tests for linting - name: Verify boilerplate run: make check-license diff --git a/Makefile-modules.mk b/Makefile-modules.mk index 4ab29c1e4..f8715c616 100644 --- a/Makefile-modules.mk +++ b/Makefile-modules.mk @@ -5,7 +5,7 @@ endif export PATH := $(MYGOBIN):$(PATH) # only set this if not already set, so importing makefiles can override it -export KUSTOMIZE_ROOT ?= $(shell pwd | sed -E 's|(.*\/kustomize).*|\1|') +export KUSTOMIZE_ROOT ?= $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\1|') include $(KUSTOMIZE_ROOT)/Makefile-tools.mk .PHONY: lint test fix fmt tidy vet @@ -13,7 +13,7 @@ include $(KUSTOMIZE_ROOT)/Makefile-tools.mk lint: $(MYGOBIN)/golangci-lint $(MYGOBIN)/golangci-lint \ -c $$KUSTOMIZE_ROOT/.golangci.yml \ - --path-prefix $(shell pwd | sed 's|.*kustomize/||') \ + --path-prefix $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\2|') \ run ./... test: diff --git a/cmd/config/internal/commands/e2e/e2econtainerconfig/Makefile b/cmd/config/internal/commands/e2e/e2econtainerconfig/Makefile index c98404d5e..08ba0ff68 100644 --- a/cmd/config/internal/commands/e2e/e2econtainerconfig/Makefile +++ b/cmd/config/internal/commands/e2e/e2econtainerconfig/Makefile @@ -1,7 +1,7 @@ # Copyright 2019 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 -.PHONY: generate license fix vet fmt test build tidy +.PHONY: generate fix vet fmt test build tidy include ../../../../../../Makefile-modules.mk diff --git a/functions/examples/application-cr/Makefile b/functions/examples/application-cr/Makefile index 756fcdde9..1243b5b47 100644 --- a/functions/examples/application-cr/Makefile +++ b/functions/examples/application-cr/Makefile @@ -1,17 +1,15 @@ # Copyright 2019 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 -.PHONY: generate license fix vet fmt test build tidy image +.PHONY: generate fix vet fmt test build tidy image -GOBIN = $(shell go env GOBIN) -ifeq ($(GOBIN),) -GOBIN = $(shell go env GOPATH)/bin -endif +export KUSTOMIZE_ROOT ?= $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\1|') +include $(KUSTOMIZE_ROOT)/Makefile-tools.mk build: (cd image && go build -v -o $(GOBIN)/config-function .) -all: generate license build fix vet fmt test lint tidy +all: generate build fix vet fmt test lint tidy fix: (cd image && go fix ./...) @@ -19,20 +17,17 @@ fix: fmt: (cd image && go fmt ./...) -generate: - (which $(GOBIN)/mdtogo || go get sigs.k8s.io/kustomize/cmd/mdtogo) - (cd image && GOBIN=$(GOBIN) go generate ./...) - -license: - (which $(GOBIN)/addlicense || go get github.com/google/addlicense) - $(GOBIN)/addlicense -y 2022 -c "The Kubernetes Authors." -f LICENSE_TEMPLATE . +generate: $(MYGOBIN)/mdtogo + (cd image && GOBIN=$(MYGOBIN) go generate ./...) tidy: (cd image && go mod tidy) -lint: - (which $(GOBIN)/golangci-lint || go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.19.1) - (cd image && $(GOBIN)/golangci-lint run ./...) +lint: $(MYGOBIN)/golangci-lint + (cd image && $(MYGOBIN)/golangci-lint \ + -c $$KUSTOMIZE_ROOT/.golangci.yml \ + --path-prefix $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\2|') \ + run ./...) test: (cd image && go test -cover ./...) diff --git a/functions/examples/injection-tshirt-sizes/Makefile b/functions/examples/injection-tshirt-sizes/Makefile index ad8918cf9..5e9ad88dc 100644 --- a/functions/examples/injection-tshirt-sizes/Makefile +++ b/functions/examples/injection-tshirt-sizes/Makefile @@ -1,17 +1,15 @@ # Copyright 2019 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 -.PHONY: generate license fix vet fmt test build tidy image +.PHONY: generate fix vet fmt test build tidy image -GOBIN = $(shell go env GOBIN) -ifeq ($(GOBIN),) -GOBIN = $(shell go env GOPATH)/bin -endif +export KUSTOMIZE_ROOT ?= $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\1|') +include $(KUSTOMIZE_ROOT)/Makefile-tools.mk build: - (cd image && go build -v -o $(GOBIN)/config-function .) + (cd image && go build -v -o $(MYGOBIN)/config-function .) -all: generate license build fix vet fmt test lint tidy +all: generate build fix vet fmt test lint tidy fix: (cd image && go fix ./...) @@ -19,20 +17,17 @@ fix: fmt: (cd image && go fmt ./...) -generate: - (which $(GOBIN)/mdtogo || go get sigs.k8s.io/kustomize/cmd/mdtogo) - (cd image && GOBIN=$(GOBIN) go generate ./...) - -license: - (which $(GOBIN)/addlicense || go get github.com/google/addlicense) - $(GOBIN)/addlicense -y 2022 -c "The Kubernetes Authors." -f LICENSE_TEMPLATE . +generate: $(MYGOBIN)/mdtogo + (cd image && GOBIN=$(MYGOBIN) go generate ./...) tidy: (cd image && go mod tidy) -lint: - (which $(GOBIN)/golangci-lint || go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.19.1) - (cd image && $(GOBIN)/golangci-lint run ./...) +lint: $(MYGOBIN)/golangci-lint + (cd image && $(MYGOBIN)/golangci-lint \ + -c $$KUSTOMIZE_ROOT/.golangci.yml \ + --path-prefix $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\2|') \ + run ./...) test: (cd image && go test -cover ./...) diff --git a/functions/examples/template-go-nginx/Makefile b/functions/examples/template-go-nginx/Makefile index 0629f60e6..2b655157f 100644 --- a/functions/examples/template-go-nginx/Makefile +++ b/functions/examples/template-go-nginx/Makefile @@ -1,17 +1,15 @@ # Copyright 2019 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 -.PHONY: generate license fix vet fmt test build tidy image +.PHONY: generate fix vet fmt test build tidy image -GOBIN = $(shell go env GOBIN) -ifeq ($(GOBIN),) -GOBIN = $(shell go env GOPATH)/bin -endif +export KUSTOMIZE_ROOT ?= $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\1|') +include $(KUSTOMIZE_ROOT)/Makefile-tools.mk build: (cd image && go build -v -o $(GOBIN)/config-function .) -all: generate license build fix vet fmt test lint tidy +all: generate build fix vet fmt test lint tidy fix: (cd image && go fix ./...) @@ -19,20 +17,17 @@ fix: fmt: (cd image && go fmt ./...) -generate: - (which $(GOBIN)/mdtogo || go get sigs.k8s.io/kustomize/cmd/mdtogo) - (cd image && GOBIN=$(GOBIN) go generate ./...) - -license: - (which $(GOBIN)/addlicense || go get github.com/google/addlicense) - $(GOBIN)/addlicense -y 2022 -c "The Kubernetes Authors." -f LICENSE_TEMPLATE . +generate: $(MYGOBIN)/mdtogo + (cd image && GOBIN=$(MYGOBIN) go generate ./...) tidy: (cd image && go mod tidy) -lint: - (which $(GOBIN)/golangci-lint || go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.19.1) - (cd image && $(GOBIN)/golangci-lint run ./...) +lint: $(MYGOBIN)/golangci-lint + (cd image && $(MYGOBIN)/golangci-lint \ + -c $$KUSTOMIZE_ROOT/.golangci.yml \ + --path-prefix $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\2|') \ + run ./...) test: (cd image && go test -cover ./...) diff --git a/functions/examples/template-heredoc-cockroachdb/Makefile b/functions/examples/template-heredoc-cockroachdb/Makefile index 96bab5307..4452033b8 100644 --- a/functions/examples/template-heredoc-cockroachdb/Makefile +++ b/functions/examples/template-heredoc-cockroachdb/Makefile @@ -1,18 +1,10 @@ # Copyright 2019 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 -.PHONY: license image +.PHONY: image -GOBIN = $(shell go env GOBIN) -ifeq ($(GOBIN),) -GOBIN = $(shell go env GOPATH)/bin -endif - -license: - (which $(GOBIN)/addlicense || go get github.com/google/addlicense) - $(GOBIN)/addlicense -y 2022 -c "The Kubernetes Authors." -f LICENSE_TEMPLATE . - -all: license +all: + true image: docker build image -t gcr.io/kustomize-functions/example-cockroachdb:v0.1.0 diff --git a/functions/examples/validator-kubeval/Makefile b/functions/examples/validator-kubeval/Makefile index a87cd64b6..b34a462f3 100644 --- a/functions/examples/validator-kubeval/Makefile +++ b/functions/examples/validator-kubeval/Makefile @@ -1,17 +1,15 @@ # Copyright 2019 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 -.PHONY: generate license fix vet fmt test build tidy image +.PHONY: generate fix vet fmt test build tidy image -GOBIN = $(shell go env GOBIN) -ifeq ($(GOBIN),) -GOBIN = $(shell go env GOPATH)/bin -endif +export KUSTOMIZE_ROOT ?= $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\1|') +include $(KUSTOMIZE_ROOT)/Makefile-tools.mk build: (cd image && go build -v -o $(GOBIN)/config-function .) -all: generate license build fix vet fmt test lint tidy +all: generate build fix vet fmt test lint tidy fix: (cd image && go fix ./...) @@ -19,20 +17,17 @@ fix: fmt: (cd image && go fmt ./...) -generate: - (which $(GOBIN)/mdtogo || go get sigs.k8s.io/kustomize/cmd/mdtogo) - (cd image && GOBIN=$(GOBIN) go generate ./...) - -license: - (which $(GOBIN)/addlicense || go get github.com/google/addlicense) - $(GOBIN)/addlicense -y 2022 -c "The Kubernetes Authors." -f LICENSE_TEMPLATE . +generate: $(MYGOBIN)/mdtogo + (cd image && GOBIN=$(MYGOBIN) go generate ./...) tidy: (cd image && go mod tidy) -lint: - (which $(GOBIN)/golangci-lint || go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.19.1) - (cd image && $(GOBIN)/golangci-lint run ./...) +lint: $(MYGOBIN)/golangci-lint + (cd image && $(MYGOBIN)/golangci-lint \ + -c $$KUSTOMIZE_ROOT/.golangci.yml \ + --path-prefix $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\2|') \ + run ./...) test: (cd image && go test -cover ./...) diff --git a/functions/examples/validator-resource-requests/Makefile b/functions/examples/validator-resource-requests/Makefile index 145394976..0de3a0634 100644 --- a/functions/examples/validator-resource-requests/Makefile +++ b/functions/examples/validator-resource-requests/Makefile @@ -1,17 +1,15 @@ # Copyright 2019 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 -.PHONY: generate license fix vet fmt test build tidy image +.PHONY: generate fix vet fmt test build tidy image -GOBIN = $(shell go env GOBIN) -ifeq ($(GOBIN),) -GOBIN = $(shell go env GOPATH)/bin -endif +export KUSTOMIZE_ROOT ?= $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\1|') +include $(KUSTOMIZE_ROOT)/Makefile-tools.mk build: (cd image && go build -v -o $(GOBIN)/config-function .) -all: generate license build fix vet fmt test lint tidy +all: generate build fix vet fmt test lint tidy fix: (cd image && go fix ./...) @@ -19,20 +17,17 @@ fix: fmt: (cd image && go fmt ./...) -generate: - (which $(GOBIN)/mdtogo || go get sigs.k8s.io/kustomize/cmd/mdtogo) - (cd image && GOBIN=$(GOBIN) go generate ./...) - -license: - (which $(GOBIN)/addlicense || go get github.com/google/addlicense) - $(GOBIN)/addlicense -y 2022 -c "The Kubernetes Authors." -f LICENSE_TEMPLATE . +generate: $(MYGOBIN)/mdtogo + (cd image && GOBIN=$(MYGOBIN) go generate ./...) tidy: (cd image && go mod tidy) -lint: - (which $(GOBIN)/golangci-lint || go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.19.1) - (cd image && $(GOBIN)/golangci-lint run ./...) +lint: $(MYGOBIN)/golangci-lint + (cd image && $(MYGOBIN)/golangci-lint \ + -c $$KUSTOMIZE_ROOT/.golangci.yml \ + --path-prefix $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\2|') \ + run ./...) test: (cd image && go test -cover ./...) diff --git a/hack/add-license.sh b/hack/add-license.sh index 18af2fe09..a9011ce28 100755 --- a/hack/add-license.sh +++ b/hack/add-license.sh @@ -34,11 +34,13 @@ args=( ) if [[ $mode == "check" ]]; then args+=(-check) + if ! addlicense "${args[@]}" . ; then + set +x + echo -e "\n------------------------------------------------------------------------" + echo "Error: license missing in one or more files. Run \`$0 run\` to update them." + exit 1 + fi + exit 0 fi -if ! addlicense "${args[@]}" . ; then - set +x - echo -e "\n------------------------------------------------------------------------" - echo "Error: license missing in one or more files. Run \`$0 run\` to update them." - exit 1 -fi +addlicense "${args[@]}" . diff --git a/plugin/someteam.example.com/v1/validator/Makefile b/plugin/someteam.example.com/v1/validator/Makefile index fa1faf7b5..86c719965 100644 --- a/plugin/someteam.example.com/v1/validator/Makefile +++ b/plugin/someteam.example.com/v1/validator/Makefile @@ -1,5 +1,7 @@ # Copyright 2022 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 +include ./../../../../Makefile-modules.mk + lint: echo "Skipping lint for broken module someteam.example.com/v1/validator" diff --git a/plugin/untested/v1/gogetter/Makefile b/plugin/untested/v1/gogetter/Makefile index cdafb4ab9..b8a600717 100644 --- a/plugin/untested/v1/gogetter/Makefile +++ b/plugin/untested/v1/gogetter/Makefile @@ -1,5 +1,7 @@ # Copyright 2022 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 +include ./../../../../Makefile-modules.mk + lint: echo "Skipping lint for broken module untested/v1/gogetter"