-
Notifications
You must be signed in to change notification settings - Fork 400
/
Makefile
141 lines (113 loc) · 4.43 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env bash
# Copyright 2024 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# If you update this file, please follow
# https://suva.sh/posts/well-documented-makefiles
## --------------------------------------
## General
## --------------------------------------
SHELL:=/usr/bin/env bash
.DEFAULT_GOAL:=help
# Use GOPROXY environment variable if set
GOPROXY := $(shell go env GOPROXY)
ifeq ($(GOPROXY),)
GOPROXY := https://proxy.golang.org
endif
export GOPROXY
# Active module mode, as we use go modules to manage dependencies
export GO111MODULE=on
# Tools.
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/golangci-lint)
GO_INSTALL := ./hack/go-install.sh
## --------------------------------------
## Binaries
## --------------------------------------
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT_VER := $(shell cat .github/workflows/golangci-lint.yml | grep [[:space:]]version: | sed 's/.*version: //')
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
$(GOLANGCI_LINT): # Build golangci-lint from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOLANGCI_LINT_PKG) $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
## --------------------------------------
## Linting
## --------------------------------------
.PHONY: lint
lint: $(GOLANGCI_LINT) ## Lint codebase
$(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS)
cd tools/setup-envtest; $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS)
.PHONY: lint-fix
lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter.
GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint
## --------------------------------------
## Testing
## --------------------------------------
.PHONY: test
test: ## Run the test.sh script which will check all.
TRACE=1 ./test.sh
test-all:
$(MAKE) test
.PHONY: modules
modules: ## Runs go mod to ensure modules are up to date.
go mod tidy
## --------------------------------------
## Cleanup / Verification
## --------------------------------------
.PHONY: clean
clean: ## Cleanup.
$(GOLANGCI_LINT) cache clean
$(MAKE) clean-bin
.PHONY: clean-bin
clean-bin: ## Remove all generated binaries.
rm -rf hack/tools/bin
.PHONE: clean-release
clean-release: ## Remove all generated release binaries.
rm -rf $(RELEASE_DIR)
## --------------------------------------
## Envtest Build
## --------------------------------------
RELEASE_DIR := out
.PHONY: $(RELEASE_DIR)
$(RELEASE_DIR):
mkdir -p $(RELEASE_DIR)/
.PHONY: release-envtest
release-envtest:
./hack/envtest/build.sh
.PHONY: release-package-envtest
release-package-envtest: clean-release ## Build the envtest binaries by operating system.
OS=linux ARCH=amd64 $(MAKE) release-envtest-docker-build
OS=linux ARCH=arm64 $(MAKE) release-envtest-docker-build
OS=linux ARCH=ppc64le $(MAKE) release-envtest-docker-build
OS=linux ARCH=s390x $(MAKE) release-envtest-docker-build
OS=darwin ARCH=amd64 $(MAKE) release-envtest-docker-build
OS=darwin ARCH=arm64 $(MAKE) release-envtest-docker-build
OS=windows ARCH=amd64 $(MAKE) release-envtest-docker-build
.PHONY: release-envtest-docker-build
release-envtest-docker-build: $(RELEASE_DIR) ## Build the envtest binaries.
@: $(if $(GO_VERSION),,$(error GO_VERSION is not set))
@: $(if $(KUBERNETES_VERSION),,$(error KUBERNETES_VERSION is not set))
@: $(if $(ETCD_VERSION),,$(error ETCD_VERSION is not set))
@: $(if $(OS),,$(error OS is not set))
@: $(if $(ARCH),,$(error ARCH is not set))
docker buildx build \
--file ./hack/envtest/$(OS)/Dockerfile \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg KUBERNETES_VERSION=$(KUBERNETES_VERSION) \
--build-arg ETCD_VERSION=$(ETCD_VERSION) \
--build-arg OS=$(OS) \
--build-arg ARCH=$(ARCH) \
--tag sigs.k8s.io/controller-tools/envtest:$(KUBERNETES_VERSION)-$(OS)-$(ARCH) \
--output type=local,dest=$(RELEASE_DIR) \
.