-
Notifications
You must be signed in to change notification settings - Fork 58
/
Makefile.tools
184 lines (160 loc) · 5.45 KB
/
Makefile.tools
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
SHELL=/usr/bin/env bash -o pipefail
## Tools
TOOLS_DIR = $(shell pwd)/tmp/bin
## NOTE: each tool must have a version that will be recorded in .github/tools
# The .github/tools file's hash is used to compute the key for cache in github
# see: .github/tools-cache/action.yaml
CONTROLLER_GEN=$(TOOLS_DIR)/controller-gen
CONTROLLER_GEN_VERSION= v0.16.2
KUSTOMIZE=$(TOOLS_DIR)/kustomize
KUSTOMIZE_VERSION= v4.5.2
OPERATOR_SDK = $(TOOLS_DIR)/operator-sdk
OPERATOR_SDK_VERSION = v1.37.0
OPM=$(TOOLS_DIR)/opm
OPM_VERSION = v1.47.0
GOLANGCI_LINT=$(TOOLS_DIR)/golangci-lint
GOLANGCI_LINT_VERSION = v1.61.0
## NOTE: promq does not have any releases, so we use a fake version starting with v0.0.1
# thus to upgrade/invalidate the github cache, increment the value
PROMQ = $(TOOLS_DIR)/promq
PROMQ_VERSION = v0.0.1
# NOTE: oc is NOT downloadable using the OC_VERSION in its URL, so this has to be manually updated
OC = $(TOOLS_DIR)/oc
OC_VERSION = v4.8.11
CRDOC = $(TOOLS_DIR)/crdoc
CRDOC_VERSION = v0.5.2
SHELLCHECK = $(TOOLS_DIR)/shellcheck
SHELLCHECK_VERSION = 0.10.0
$(TOOLS_DIR):
@mkdir -p $(TOOLS_DIR)
.PHONY: controller-gen
$(CONTROLLER_GEN) controller-gen: $(TOOLS_DIR)
@{ \
set -ex ;\
GOBIN=$(TOOLS_DIR) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) ;\
}
.PHONY: golangci-lint
$(GOLANGCI_LINT) golangci-lint: $(TOOLS_DIR)
@{ \
set -ex ;\
GOBIN=$(TOOLS_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) ;\
}
# NOTE: kustomize does not support `go install` hence this workaround to install
# it by creating an tmp module and using go get to download the precise version
# needed for the project
# see: https://github.com/kubernetes-sigs/kustomize/issues/3618
.PHONY: kustomize
$(KUSTOMIZE) kustomize: $(TOOLS_DIR)
@{ \
set -ex ;\
[[ -f $(KUSTOMIZE) ]] && exit 0 ;\
GOBIN=$(TOOLS_DIR) go install sigs.k8s.io/kustomize/kustomize/v4@$(KUSTOMIZE_VERSION) ;\
}
.PHONY: operator-sdk
$(OPERATOR_SDK) operator-sdk: $(TOOLS_DIR)
@{ \
set -ex ;\
[[ -f $(OPERATOR_SDK) ]] && \
[[ "$(shell $(OPERATOR_SDK) version | awk '{print $$3}' | tr -d ,)" == $(OPERATOR_SDK_VERSION) ]] && { \
echo "operator-sdk up to date" ;\
exit 0 ;\
} ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
chmod +x $(OPERATOR_SDK) ;\
}
.PHONY: opm
$(OPM) opm: $(TOOLS_DIR)
@{ \
[[ -f $(OPM) ]] && exit 0 ;\
set -ex ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/$(OPM_VERSION)/$${OS}-$${ARCH}-opm ;\
chmod +x $(OPM) ;\
}
.PHONY: promq
$(PROMQ) promq: $(TOOLS_DIR)
@{ \
set -ex ;\
[[ -f $(PROMQ) ]] && exit 0 ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
echo "Downloading promq" ;\
git clone --depth=1 https://github.com/kubernetes-sigs/instrumentation-tools ;\
cd instrumentation-tools ;\
go build -o $(PROMQ) . ;\
rm -rf $$TMP_DIR ;\
}
.PHONY: oc
$(OC) oc: $(TOOLS_DIR)
@{ \
set -ex ;\
[[ -f $(OC) ]] && exit 0 ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OC) https://mirror.openshift.com/pub/openshift-v4/$${ARCH}/clients/oc/latest/$${OS}/oc.tar.gz ;\
tar -xf $(TOOLS_DIR)/oc -C $(TOOLS_DIR) ;\
rm -f $(TOOLS_DIR)/README.md ;\
$(OC) version ;\
version=$(OC_VERSION) ;\
$(OC) version | grep -q $${version##v} ;\
}
.PHONY: crdoc
$(CRDOC) crdoc: $(TOOLS_DIR)
@{ \
set -ex ;\
[[ -f $(CRDOC) ]] && exit 0 ;\
GOBIN=$(TOOLS_DIR) go install fybrik.io/crdoc@$(CRDOC_VERSION) ;\
}
.PHONY: shellcheck
$(SHELLCHECK) shellcheck: $(TOOLS_DIR)
@{ \
set -ex ;\
[[ -f $(SHELLCHECK) ]] && exit 0 ;\
cd $$(mktemp -d) ;\
OS=$(shell go env GOOS) && ARCH=$(shell uname -m) && \
curl -sSLo shellcheck-stable.tar.xz https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.$${OS}.$${ARCH}.tar.xz ;\
tar -xJf shellcheck-stable.tar.xz ;\
cp shellcheck-stable/shellcheck $(SHELLCHECK) ;\
version=$(SHELLCHECK_VERSION) ;\
$(SHELLCHECK) -V | grep -q $${version##v} ;\
}
# Install all required tools
.PHONY: tools
tools: $(CONTROLLER_GEN) \
$(KUSTOMIZE) \
$(OC) \
$(OPERATOR_SDK) \
$(OPM) \
$(PROMQ) \
$(CRDOC) \
$(GOLANGCI_LINT) \
$(SHELLCHECK)
@{ \
set -ex ;\
tools_file=.github/tools ;\
echo '# DO NOT EDIT! Autogenerated by make tools' > $$tools_file ;\
echo '' >> $$tools_file ;\
echo $$(basename $(GOLANGCI_LINT)) $(GOLANGCI_LINT_VERSION) >> $$tools_file ;\
echo $$(basename $(CONTROLLER_GEN)) $(CONTROLLER_GEN_VERSION) >> $$tools_file ;\
echo $$(basename $(KUSTOMIZE)) $(KUSTOMIZE_VERSION) >> $$tools_file ;\
echo $$(basename $(OC)) $(OC_VERSION) >> $$tools_file ;\
echo $$(basename $(OPERATOR_SDK)) $(OPERATOR_SDK_VERSION) >> $$tools_file ;\
echo $$(basename $(OPM)) $(OPM_VERSION) >> $$tools_file ;\
echo $$(basename $(PROMQ)) $(PROMQ_VERSION) >> $$tools_file ;\
echo $$(basename $(CRDOC)) $(CRDOC_VERSION) >> $$tools_file ; \
echo $$(basename $(SHELLCHECK)) $(SHELLCHECK_VERSION) >> $$tools_file ;\
}
.PHONY: clean-tools
clean-tools:
rm -rf $(TOOLS_DIR)
.PHONY: validate-tools
validate-tools:
@$(GOLANGCI_LINT) --version
@$(CONTROLLER_GEN) --version
@$(KUSTOMIZE) version
@$(OC) version --client
@$(OPERATOR_SDK) version
@$(OPM) version
@$(PROMQ) --help | head -n 2
@$(CRDOC) --help | head -n 3
@$(SHELLCHECK) -V | head -n 2