Debian Codegraph @

Makefile

raw
1 # Copyright 2019 The Kubernetes Authors.
2 # SPDX-License-Identifier: Apache-2.0
3 #
4 # Makefile for kustomize CLI and API.
5
6 LATEST_RELEASE=v5.8.0
7
8 SHELL := /usr/bin/env bash
9 GOOS = $(shell go env GOOS)
10 GOARCH = $(shell go env GOARCH)
11 MYGOBIN = $(shell go env GOBIN)
12 ifeq ($(MYGOBIN),)
13 MYGOBIN = $(shell go env GOPATH)/bin
14 endif
15 export PATH := $(MYGOBIN):$(PATH)
16
17 # Provide defaults for REPO_OWNER and REPO_NAME if not present.
18 # Typically these values would be provided by Prow.
19 ifndef REPO_OWNER
20 REPO_OWNER := "kubernetes-sigs"
21 endif
22
23 ifndef REPO_NAME
24 REPO_NAME := "kustomize"
25 endif
26
27
28 # --- Plugins ---
29 include Makefile-plugins.mk
30
31
32 # --- Tool management ---
33 include Makefile-tools.mk
34
35 .PHONY: install-tools
36 install-tools: \
37 install-local-tools \
38 install-out-of-tree-tools
39
40 .PHONY: uninstall-tools
41 uninstall-tools: \
42 uninstall-local-tools \
43 uninstall-out-of-tree-tools
44
45 .PHONY: install-local-tools
46 install-local-tools: \
47 $(MYGOBIN)/gorepomod \
48 $(MYGOBIN)/k8scopy \
49 $(MYGOBIN)/pluginator
50
51 .PHONY: uninstall-local-tools
52 uninstall-local-tools:
53 rm -f $(MYGOBIN)/gorepomod
54 rm -f $(MYGOBIN)/k8scopy
55 rm -f $(MYGOBIN)/pluginator
56
57 # Build from local source.
58 $(MYGOBIN)/gorepomod:
59 cd cmd/gorepomod && go install .
60
61 # Build from local source.
62 $(MYGOBIN)/k8scopy:
63 cd cmd/k8scopy && go install .
64
65 # Build from local source.
66 $(MYGOBIN)/pluginator:
67 cd cmd/pluginator && go install .
68
69
70 # --- Build targets ---
71
72 # Build from local source.
73 $(MYGOBIN)/kustomize: build-kustomize-api
74 cd kustomize && go install -ldflags \
75 "-X sigs.k8s.io/kustomize/api/provenance.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
76 -X sigs.k8s.io/kustomize/api/provenance.version=$(shell git describe --tags --always --dirty)" \
77 .
78
79 kustomize: $(MYGOBIN)/kustomize
80
81 # Used to add non-default compilation flags when experimenting with
82 # plugin-to-api compatibility checks.
83 .PHONY: build-kustomize-api
84 build-kustomize-api: $(MYGOBIN)/goimports $(builtinplugins)
85 cd api && $(MAKE) build
86
87 .PHONY: generate-kustomize-api
88 generate-kustomize-api:
89 cd api && $(MAKE) generate
90
91
92 # --- Verification targets ---
93 .PHONY: verify-kustomize-repo
94 verify-kustomize-repo: \
95 install-tools \
96 lint \
97 check-license \
98 test-unit-all \
99 build-non-plugin-all \
100 test-go-mod \
101 test-examples-kustomize-against-HEAD \
102 test-examples-kustomize-against-latest-release
103
104 # The following target referenced by a file in
105 # https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-sigs/kustomize
106 .PHONY: prow-presubmit-check
107 prow-presubmit-check: \
108 install-tools \
109 workspace-sync \
110 generate-kustomize-builtin-plugins \
111 builtin-plugins-diff \
112 test-unit-kustomize-plugins \
113 test-go-mod \
114 build-non-plugin-all \
115 test-examples-kustomize-against-HEAD \
116 test-examples-kustomize-against-latest-release
117
118 .PHONY: license
119 license: $(MYGOBIN)/addlicense
120 ./hack/add-license.sh run
121
122 .PHONY: check-license
123 check-license: $(MYGOBIN)/addlicense
124 ./hack/add-license.sh check
125
126 .PHONY: lint
127 lint: $(MYGOBIN)/golangci-lint $(MYGOBIN)/goimports $(builtinplugins)
128 ./hack/for-each-module.sh "make lint"
129
130 .PHONY: apidiff
131 apidiff: $(MYGOBIN)/go-apidiff ## Run the go-apidiff to verify any API differences compared with origin/master
132 go-apidiff master --compare-imports --print-compatible --repo-path=.
133
134 .PHONY: test-unit-all
135 test-unit-all: \
136 test-unit-non-plugin \
137 test-unit-kustomize-plugins
138
139 .PHONY: test-unit-non-plugin
140 test-unit-non-plugin:
141 ./hack/for-each-module.sh "make test" "./plugin/*" 20
142
143 # This target is used by our Github Actions CI to run unit tests for all non-plugin and non-released modules in multiple GOOS environments.
144 .PHONY: test-unit-non-plugin-and-non-released
145 test-unit-non-plugin-and-non-released:
146 ./hack/for-each-module.sh "make test" "./plugin/*|./kyaml/go.mod|./cmd/config/go.mod|./api/go.mod|./kustomize/go.mod" 16
147
148 .PHONY: build-non-plugin-all
149 build-non-plugin-all:
150 ./hack/for-each-module.sh "make build" "./plugin/*" 20
151
152 .PHONY: test-unit-kustomize-plugins
153 test-unit-kustomize-plugins: build-kustomize-external-go-plugin
154 ./hack/testUnitKustomizePlugins.sh
155
156 .PHONY: functions-examples-all
157 functions-examples-all:
158 for dir in $(abspath $(wildcard functions/examples/*/.)); do \
159 echo -e "\n---Running make tasks for function $$dir---"; \
160 set -e; \
161 cd $$dir; $(MAKE) all; \
162 done
163
164 test-go-mod:
165 ./hack/for-each-module.sh "go mod tidy -v"
166
167 .PHONY:
168 verify-kustomize-e2e: $(MYGOBIN)/mdrip $(MYGOBIN)/kind
169 ( \
170 set -e; \
171 /bin/rm -f $(MYGOBIN)/kustomize; \
172 echo "Installing kustomize from ."; \
173 cd kustomize; go install .; cd ..; \
174 ./hack/testExamplesE2EAgainstKustomize.sh .; \
175 )
176
177 .PHONY:
178 test-examples-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip
179 ./hack/testExamplesAgainstKustomize.sh HEAD
180
181 .PHONY:
182 test-examples-kustomize-against-latest-release: $(MYGOBIN)/mdrip
183 ./hack/testExamplesAgainstKustomize.sh v5@$(LATEST_RELEASE)
184
185 # Pushes dependencies in the go.work file back to go.mod files of each workspace module.
186 .PHONY: workspace-sync
187 workspace-sync:
188 go work sync
189 ./hack/doGoMod.sh tidy
190
191 # --- Cleanup targets ---
192 .PHONY: clean
193 clean: clean-kustomize-external-go-plugin uninstall-tools
194 go clean --cache
195 rm -f $(builtinplugins)
196 rm -f $(MYGOBIN)/kustomize
197
198 # Nuke the site from orbit. It's the only way to be sure.
199 .PHONY: nuke
200 nuke: clean
201 go clean --modcache