Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit a7e4f26

Browse files
committed
add kubebuilder suggested e2e and lint targets
Add the test-e2e, lint, and lint-fix targets that are suggested by kubebuilder, with adjustments to work for COSI monorepo. Signed-off-by: Blaine Gardner <[email protected]>
1 parent e9d5dfb commit a7e4f26

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
release-tools
66
.idea
77
travis.yml
8-
8+
.cache

Makefile

+48
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ vet: vet.client vet.controller vet.sidecar ## Vet code
6060
.PHONY: test
6161
test: .test.proto test.client test.controller test.sidecar ## Run tests including unit tests
6262

63+
.PHONY: test-e2e
64+
test-e2e: # Run e2e tests
65+
@echo "unimplemented placeholder"
66+
67+
.PHONY: lint
68+
lint: golangci-lint.client golangci-lint.controller golangci-lint.sidecar ## Run all linters (suggest `make -k`)
69+
70+
.PHONY: lint-fix
71+
lint-fix: golangci-lint-fix.client golangci-lint-fix.controller golangci-lint-fix.sidecar ## Run all linters and perform fixes where possible (suggest `make -k`)
72+
6373

6474
##@ Build
6575

@@ -81,7 +91,38 @@ clean:
8191
## Clean build environment and cached tools
8292
clobber:
8393
$(MAKE) -C proto clobber
94+
rm -rf $(CURDIR)/.cache
8495

96+
##
97+
## === TOOLS === #
98+
99+
GOLANGCI_LINT_VERSION ?= v1.59.1
100+
101+
TOOLBIN ?= $(CURDIR)/.cache/tools
102+
$(TOOLBIN):
103+
mkdir -p $(TOOLBIN)
104+
105+
GOLANGCI_LINT ?= $(TOOLBIN)/golangci-lint
106+
# .PHONY: golangci-lint
107+
# golangci-lint: $(GOLANGCI_LINT)
108+
$(GOLANGCI_LINT): $(TOOLBIN)
109+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
110+
111+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
112+
# $1 - target path with name of binary
113+
# $2 - package url which can be installed
114+
# $3 - specific version of package
115+
define go-install-tool
116+
@[ -f "$(1)-$(3)" ] || { \
117+
set -e; \
118+
package=$(2)@$(3) ;\
119+
echo "Downloading $${package}" ;\
120+
rm -f $(1) || true ;\
121+
GOBIN=$(TOOLBIN) go install $${package} ;\
122+
mv $(1) $(1)-$(3) ;\
123+
} ;\
124+
ln -sf $(1)-$(3) $(1)
125+
endef
85126

86127
##
87128
## === INTERMEDIATES === #
@@ -101,6 +142,13 @@ vet.%: FORCE
101142
test.%: fmt.% vet.% FORCE
102143
cd $* && go test ./...
103144

145+
# golangci-lint --new flag only complains about new code
146+
golangci-lint.%: $(GOLANGCI_LINT)
147+
cd $* && $(GOLANGCI_LINT) run --config $(CURDIR)/.golangci.yaml --new
148+
149+
golangci-lint-fix.%: $(GOLANGCI_LINT)
150+
cd $* && $(GOLANGCI_LINT) run --config $(CURDIR)/.golangci.yaml --new --fix
151+
104152
.PHONY: .test.proto
105153
.test.proto: # gRPC proto has a special unit test
106154
$(MAKE) -C proto check

0 commit comments

Comments
 (0)