Skip to content

Commit f7bf43d

Browse files
committed
chore(make): add generate and vendor rules
Add the generate and vendor rules to the Makefile. The generate rule uses controller-gen to generate deepcopy types. The vendor rule updates vendored dependencies and is a prereq of generate.
1 parent fcd3fd6 commit f7bf43d

File tree

5 files changed

+97
-27
lines changed

5 files changed

+97
-27
lines changed

Makefile

+22-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ ifeq ($(BUILD_VERBOSE),1)
88
else
99
Q = @
1010
endif
11+
12+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
13+
ifeq (,$(shell go env GOBIN))
14+
GOBIN=$(shell go env GOPATH)/bin
15+
else
16+
GOBIN=$(shell go env GOBIN)
17+
endif
1118

1219
REPO = github.com/operator-framework/api
1320
BUILD_PATH = $(REPO)/cmd/operator-verify
@@ -23,7 +30,7 @@ help: ## Show this help screen
2330

2431
.PHONY: install
2532

26-
install: ## Build & install the operator-verify
33+
install: ## Build & install operator-verify
2734

2835
$(Q)go install \
2936
-gcflags "all=-trimpath=${GOPATH}" \
@@ -35,22 +42,22 @@ install: ## Build & install the operator-verify
3542
$(BUILD_PATH)
3643

3744
# Code management.
38-
.PHONY: format tidy clean
45+
.PHONY: format tidy clean vendor generate
3946

4047
format: ## Format the source code
4148
$(Q)go fmt $(PKGS)
4249

4350
tidy: ## Update dependencies
4451
$(Q)go mod tidy -v
4552

53+
vendor: tidy ## Update vendor directory
54+
$(Q)go mod vendor
55+
4656
clean: ## Clean up the build artifacts
4757
$(Q)rm -rf build
4858

49-
##############################
50-
# Tests #
51-
##############################
52-
53-
##@ Tests
59+
generate: controller-gen ## Generate code
60+
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..."
5461

5562
# Static tests.
5663
.PHONY: test test-unit
@@ -59,4 +66,11 @@ test: test-unit ## Run the tests
5966

6067
TEST_PKGS:=$(shell go list ./...)
6168
test-unit: ## Run the unit tests
62-
$(Q)go test -short ${TEST_PKGS}
69+
$(Q)go test -count=1 -short ${TEST_PKGS}
70+
71+
# Utilities.
72+
.PHONY: controller-gen
73+
74+
controller-gen: vendor ## Find or download controller-gen
75+
CONTROLLER_GEN=$(Q)go run -mod=vendor ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen
76+

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ require (
1414
k8s.io/apiextensions-apiserver v0.17.3
1515
k8s.io/apimachinery v0.17.3
1616
k8s.io/client-go v0.17.3
17+
sigs.k8s.io/controller-runtime v0.5.2
18+
sigs.k8s.io/controller-tools v0.2.8
1719
)

0 commit comments

Comments
 (0)