1+
2+ # Setting SHELL to bash allows bash commands to be executed by recipes.
3+ # Options are set to exit when a recipe line exits non-zero or a piped command fails.
4+ SHELL = /usr/bin/env bash -o pipefail
5+ .SHELLFLAGS = -ec
6+
7+ # Set MAKEFLAGS to suppress entering/leaving directory messages
8+ MAKEFLAGS += --no-print-directory
9+
10+ BUILD_PATH ?= $(shell pwd)
11+ HACK_DIR ?= $(shell cd hack 2>/dev/null && pwd)
12+ LOCALBIN ?= $(BUILD_PATH ) /bin
13+
14+ OS := $(shell go env GOOS)
15+ ARCH := $(shell go env GOARCH)
16+
17+ GO ?= go
18+ SHELLCHECK ?= shellcheck
19+ OSV_SCANNER ?= osv-scanner
20+ MKDOCS ?= mkdocs
21+ DOCKER ?= docker
22+ GINKGO ?= $(LOCALBIN ) /ginkgo
23+ GOLANGCI_LINT ?= $(LOCALBIN ) /golangci-lint
24+ SETUP_ENVTEST ?= $(LOCALBIN ) /setup-envtest
25+ ADDLICENSE ?= $(LOCALBIN ) /addlicense
26+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
27+ OPENAPI_GEN ?= $(LOCALBIN ) /openapi-gen
28+ CRD_REF_DOCS ?= $(LOCALBIN ) /crd-ref-docs
29+ OCM ?= $(LOCALBIN ) /ocm
30+
31+ GINKGO_VERSION ?= $(shell go list -json -m -u github.com/onsi/ginkgo/v2 | jq -r '.Version')
32+ GOLANGCI_LINT_VERSION ?= v2.10.1
33+ SETUP_ENVTEST_VERSION ?= release-0.22
34+ ADDLICENSE_VERSION ?= v1.1.1
35+ CRD_REF_DOCS_VERSION ?= v0.2.0
36+
37+ export GOPRIVATE =*.go.opendefense.cloud/testkit
38+ export GNOSUMDB =*.go.opendefense.cloud/testkit
39+ export GNOPROXY =*.go.opendefense.cloud/testkit
40+
41+ # #@ General
42+
43+ # The help target prints out all targets with their descriptions organized
44+ # beneath their categories. The categories are represented by '##@' and the
45+ # target descriptions by '##'. The awk commands is responsible for reading the
46+ # entire set of makefiles included in this invocation, looking for lines of the
47+ # file as xyz: ## something, and then pretty-format the target and help. Then,
48+ # if there's a line with ##@ something, that gets pretty-printed as a category.
49+ # More info on the usage of ANSI control characters for terminal formatting:
50+ # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
51+ # More info on the awk command:
52+ # http://linuxcommand.org/lc3_adv_awk.php
53+
54+ help : # # Display this help.
55+ @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
56+
57+ .PHONY : clean
58+ clean :
59+ rm -rf $(LOCALBIN )
60+
61+
62+ .PHONY : fmt
63+ fmt : addlicense golangci-lint # # Add license headers and format
64+ echo $(ADDLICENCE )
65+ find . -not -path ' */.*' -name ' *.go' -exec $(ADDLICENSE ) -c ' BWI GmbH and Testkit contributors' -l apache -s=only {} +
66+ $(GO ) fmt ./...
67+ $(GOLANGCI_LINT ) run --fix
68+
69+ .PHONY : mod
70+ mod : # # Do go mod tidy, download, verify
71+ @$(GO ) mod tidy
72+ @$(GO ) mod download
73+ @$(GO ) mod verify
74+
75+ .PHONY : lint
76+ lint : lint-no-golangci golangci-lint # # Run linters such as golangci-lint and addlicence checks
77+ $(GOLANGCI_LINT ) run -v
78+
79+ .PHONY : lint-no-golangci
80+ lint-no-golangci : addlicense
81+ find . -not -path ' */.*' -name ' *.go' -exec $(ADDLICENSE ) -check -l apache -s=only -check {} +
82+ shellcheck hack/* .sh
83+
84+ .PHONY : scan
85+ scan :
86+ $(OSV_SCANNER ) scan --config ./.osv-scanner.toml -r .
87+
88+ .PHONY : test
89+ test : ginkgo # # Run all tests
90+ $(GINKGO ) -r -cover --fail-fast --require-suite -covermode count --output-dir=$(BUILD_PATH ) -coverprofile=testkit.coverprofile $(testargs )
91+
92+ TIMESTAMP ?= $(shell date '+% Y% m% d% H% M% S')
93+
94+ $(LOCALBIN ) :
95+ mkdir -p $(LOCALBIN )
96+
97+ .PHONY : golangci-lint
98+ golangci-lint : $(LOCALBIN ) # # Download golangci-lint locally if necessary.
99+ @test -s $(LOCALBIN ) /golangci-lint && $(LOCALBIN ) /golangci-lint --version | grep -q $(GOLANGCI_LINT_VERSION ) || \
100+ GOBIN=$(LOCALBIN ) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION )
101+
102+ .PHONY : ginkgo
103+ ginkgo : $(LOCALBIN ) # # Download ginkgo locally if necessary.
104+ @test -s $(LOCALBIN ) /ginkgo && $(LOCALBIN ) /ginkgo version | grep -q $(subst v,,$(GINKGO_VERSION ) ) || \
105+ GOBIN=$(LOCALBIN ) go install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION )
106+
107+ .PHONY : addlicense
108+ addlicense : $(LOCALBIN ) # # Download addlicense locally if necessary.
109+ @test -s $(LOCALBIN ) /addlicense && grep -q $(ADDLICENSE_VERSION ) $(LOCALBIN ) /.addlicense-version 2> /dev/null || \
110+ GOBIN=$(LOCALBIN ) go install github.com/google/addlicense@$(ADDLICENSE_VERSION ) ; \
111+ echo $(ADDLICENSE_VERSION ) > $(LOCALBIN ) /.addlicense-version
112+
113+
114+
115+ .PHONY : crd-ref-docs
116+ crd-ref-docs : $(LOCALBIN ) # # Download crd-ref-docs locally if necessary.
117+ @test -s $(LOCALBIN ) /crd-ref-docs && $(LOCALBIN ) /crd-ref-docs --version | grep -q $(CRD_REF_DOCS_VERSION ) || \
118+ GOBIN=$(LOCALBIN ) go install github.com/elastic/crd-ref-docs@$(CRD_REF_DOCS_VERSION )
0 commit comments