forked from rhobs/observability-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.tools
257 lines (220 loc) · 7.5 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
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.11.3
KUSTOMIZE=$(TOOLS_DIR)/kustomize
KUSTOMIZE_VERSION= v4.5.2
OPERATOR_SDK = $(TOOLS_DIR)/operator-sdk
OPERATOR_SDK_VERSION = v1.24.0
OPM=$(TOOLS_DIR)/opm
OPM_VERSION = v1.26.1
GOLANGCI_LINT=$(TOOLS_DIR)/golangci-lint
GOLANGCI_LINT_VERSION = v1.52.2
## 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
# jsonnet related tools and dependencies
JSONNET = $(TOOLS_DIR)/jsonnet
JSONNET_VERSION = v0.17.0
JSONNETFMT = $(TOOLS_DIR)/jsonnetfmt
JSONNETFMT_VERSION = v0.17.0
JSONNET_LINT = $(TOOLS_DIR)/jsonnet-lint
JSONNET_LINT_VERSION = v0.17.0
JB = $(TOOLS_DIR)/jb
JB_VERSION = v0.4.0
## NOTE: gojsontoyaml 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
GOJSONTOYAML = $(TOOLS_DIR)/gojsontoyaml
GOJSONTOYAML_VERSION = 0.0.1
JSONNET_VENDOR = jsonnet/vendor
JSONNETFMT_ARGS = -n 2 --max-blank-lines 2 --string-style s --comment-style s
SHELLCHECK = $(TOOLS_DIR)/shellcheck
SHELLCHECK_VERSION = 0.9.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: jsonnet
$(JSONNET) jsonnet: $(TOOLS_DIR)
@{ \
set -ex ;\
[[ -f $(JSONNET) ]] && exit 0 ;\
GOBIN=$(TOOLS_DIR) go install github.com/google/go-jsonnet/cmd/jsonnet@latest ;\
}
.PHONY: jsonnetfmt
$(JSONNETFMT) jsonnetfmt: $(TOOLS_DIR)
@{ \
set -ex ;\
[[ -f $(JSONNETFMT) ]] && exit 0 ;\
GOBIN=$(TOOLS_DIR) go install github.com/google/go-jsonnet/cmd/jsonnetfmt@latest ;\
}
.PHONY: jsonnet-lint
$(JSONNET_LINT) jsonnet-lint: $(TOOLS_DIR)
@{ \
set -ex ;\
[[ -f $(JSONNET_LINT) ]] && exit 0 ;\
GOBIN=$(TOOLS_DIR) go install github.com/google/go-jsonnet/cmd/jsonnet-lint@latest ;\
}
.PHONY: jb
$(JB) jb: $(TOOLS_DIR)
@{ \
set -ex ;\
[[ -f $(JB) ]] && exit 0 ;\
GOBIN=$(TOOLS_DIR) go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest ;\
}
.PHONY: gojsontoyaml
$(GOJSONTOYAML) gojsontoyaml: $(TOOLS_DIR)
@{ \
set -ex ;\
[[ -f $(GOJSONTOYAML) ]] && exit 0 ;\
GOBIN=$(TOOLS_DIR) go install github.com/brancz/gojsontoyaml@latest ;\
}
.PHONY: shellcheck
$(SHELLCHECK) shellcheck: $(TOOLS_DIR)
@{ \
set -ex ;\
[[ -f $(SHELLCHECK) ]] && exit 0 ;\
cd $$(mktemp -d) ;\
curl -sSLo shellcheck-stable.tar.xz "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz";\
tar -xJf shellcheck-stable.tar.xz ;\
cp shellcheck-stable/shellcheck $(SHELLCHECK) ;\
version=$(SHELLCHECK_VERSION) ;\
$(SHELLCHECK) -V | grep -q $${version##v} ;\
}
.PHONY: jsonnet-tools
jsonnet-tools: jsonnet jsonnetfmt jsonnet-lint jb gojsontoyaml
# Install all required tools
.PHONY: tools
tools: $(CONTROLLER_GEN) \
$(KUSTOMIZE) \
$(OC) \
$(OPERATOR_SDK) \
$(OPM) \
$(PROMQ) \
$(CRDOC) \
$(GOLANGCI_LINT) \
$(SHELLCHECK) \
jsonnet-tools
@{ \
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 $(JSONNET)) $(JSONNET_VERSION) >> $$tools_file ;\
echo $$(basename $(JSONNETFMT)) $(JSONNETFMT_VERSION) >> $$tools_file ;\
echo $$(basename $(JSONNET_LINT)) $(JSONNET_LINT_VERSION) >> $$tools_file ;\
echo $$(basename $(JB)) $(JB_VERSION) >> $$tools_file ;\
echo $$(basename $(GOJSONTOYAML)) $(GOJSONTOYAML_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
@$(JSONNETFMT) --version
@$(JSONNET_LINT) --version
@$(JB) --version
@$(SHELLCHECK) -V | head -n 2