Skip to content

Commit 262e1ed

Browse files
kaovilaioadp-maintainers
authored andcommitted
Create Makefile.prow
Code-gen no longer required on verify due to vmware-tanzu#6039 Signed-off-by: Tiger Kaovilai <[email protected]> oadp-1.2: Update Makefile.prow to velero-restore-helper
1 parent b07ea92 commit 262e1ed

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

Makefile.prow

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# warning: verify this inside a container with following:
2+
# docker run -it --rm -v `pwd`:`pwd` -w `pwd` golang:1.18 bash -c "make -f Makefile.prow ci"
3+
#
4+
# otherwise unintended system changes may include, replacing your currently installed kubectl, binaries in GOBIN, files in GOPATH/src
5+
#
6+
# If formatting needs updating you can run
7+
# GOFLAGS=-mod=mod make update
8+
9+
GOFLAGS=-mod=mod
10+
CONGEN_VERSION=0.7.0
11+
CODEGEN_VERSION=0.22.2
12+
PROWBIN=/tmp/prowbin
13+
# Name of this Makefile
14+
MAKEFILE=Makefile.prow
15+
# emulate as close as possible upstream ci target
16+
# upstream ci target: verify-modules verify all test
17+
# we only need to modify verify, test, all to avoid docker usage
18+
.PHONY: ci
19+
ci:
20+
@echo "go version is: $(shell go version)"
21+
GOFLAGS=$(GOFLAGS) make verify-modules
22+
make -f $(MAKEFILE) verify all test
23+
24+
.PHONY: verify
25+
verify: goimports controller-gen kubectl #code-generator
26+
# add PROWBIN to PATH
27+
@echo Verifying with PATH=$(PROWBIN):$(PATH)
28+
# Per
29+
# https://github.com/vmware-tanzu/velero/blob/dd660882d0db96d430547f39dc3694d1c1bc19f3/Makefile#L160-L163
30+
# code-generator tools require project to be in heirarchy such as github.com/vmware-tanzu/velero
31+
# so we need to copy the project to GOPATH/src/github.com/vmware-tanzu/velero
32+
# and then run verify from there
33+
# otherwise the code-generator tools will fail
34+
mkdir -p $(GOSRC)/github.com/vmware-tanzu/
35+
cp -r . $(GOSRC)/github.com/vmware-tanzu/velero
36+
cd $(GOSRC)/github.com/vmware-tanzu/velero && \
37+
PATH=$(PROWBIN):$(PATH) GOFLAGS=$(GOFLAGS) hack/verify-all.sh
38+
39+
.PHONY: all
40+
all:
41+
GOFLAGS=$(GOFLAGS) make local
42+
GOFLAGS=$(GOFLAGS) BIN=velero-restore-helper make local
43+
44+
.PHONY: test
45+
# our test is modified to avoid docker usage
46+
test: envtest
47+
@echo Testing with KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS)
48+
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) GOFLAGS=$(GOFLAGS) hack/test.sh
49+
50+
GOPATH:=$(shell go env GOPATH)
51+
GOBIN:=$(GOPATH)/bin
52+
GOSRC:=$(GOPATH)/src
53+
# if KUBEBUILDER_ASSETS contains space, escape it
54+
KUBEBUILDER_ASSETS=$(shell echo $(shell $(GOBIN)/setup-envtest use -p path) | sed 's/ /\\ /g')
55+
.PHONY: envtest
56+
envtest: $(GOBIN)/setup-envtest
57+
$(GOBIN)/setup-envtest use -p path
58+
59+
$(GOBIN)/setup-envtest:
60+
@echo Installing envtest tools
61+
GOFLAGS= go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
62+
@echo Installed envtest tools
63+
64+
.PHONY: goimports
65+
goimports: $(GOBIN)/goimports
66+
67+
$(GOBIN)/goimports:
68+
@echo Installing goimports
69+
go install golang.org/x/tools/cmd/goimports@latest
70+
@echo Installed goimports
71+
72+
.PHONY: code-generator
73+
code-generator: $(GOSRC)/k8s.io/code-generator
74+
75+
$(GOSRC)/k8s.io/code-generator:
76+
mkdir -p $(GOSRC)/k8s.io/
77+
cd $(GOSRC)/k8s.io/ && git clone -b v$(CODEGEN_VERSION) https://github.com/kubernetes/code-generator
78+
79+
.PHONY: controller-gen
80+
controller-gen: $(GOBIN)/controller-gen
81+
82+
$(GOBIN)/controller-gen:
83+
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v$(CONGEN_VERSION)
84+
85+
.PHONY: kubectl
86+
kubectl: $(PROWBIN)/kubectl
87+
88+
$(PROWBIN)/kubectl:
89+
curl -LO "https://dl.k8s.io/release/$(shell curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
90+
chmod +x ./kubectl
91+
mkdir -p $(PROWBIN)
92+
mv ./kubectl $(PROWBIN)

0 commit comments

Comments
 (0)