-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
189 lines (147 loc) · 6.58 KB
/
Makefile
File metadata and controls
189 lines (147 loc) · 6.58 KB
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
.PHONY: all
all: fmt lint test test-examples build-examples
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk command is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
PRETTIER ?= $(LOCALBIN)/prettier
ENVTEST ?= $(LOCALBIN)/setup-envtest
GINKGO ?= $(LOCALBIN)/ginkgo
PRETTIER_VERSION ?= 3.8.1
GINKGO_VERSION ?= $(shell go list -m -f "{{ .Version }}" github.com/onsi/ginkgo/v2)
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
.PHONY: setup-envtest
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
exit 1; \
}
.PHONY: envtest
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
.PHONY: ginkgo
ginkgo: $(GINKGO) ## Download ginkgo CLI locally if necessary.
$(GINKGO): $(LOCALBIN)
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo,$(GINKGO_VERSION))
##@ AI Instructions
AI_BASE := .ai/base.md
AI_REVIEW := .ai/review.md
.PHONY: ai-instructions
ai-instructions: ai-instructions-gen fmt-md
.PHONY: ai-instructions-gen
ai-instructions-gen: ## Generate all AI instruction files from source templates in .ai/
cp $(AI_BASE) CLAUDE.md
@mkdir -p .junie
cp $(AI_BASE) .junie/guidelines.md
@mkdir -p .github
cp $(AI_REVIEW) .github/copilot-review-guidelines.md
@{ \
cat $(AI_BASE); \
printf '\n\n---\n\n## Code Review\n\nWhen reviewing pull requests, apply the standards in [`.github/copilot-review-guidelines.md`](copilot-review-guidelines.md).\n'; \
} > .github/copilot-instructions.md
##@ Development
.PHONY: fmt
fmt: fmt-go fmt-md ## Run all formatting in the project
.PHONY: fmt-go
fmt-go: ## Format Go source files.
go fmt ./...
.PHONY: fmt-md
fmt-md: prettier ## Format Markdown files.
$(PRETTIER) --write '**/*.md' --ignore-path .gitignore
.PHONY: prettier
prettier: $(PRETTIER) ## Download prettier locally if necessary.
$(PRETTIER): $(LOCALBIN)
@[ -f $(PRETTIER) ] || { \
set -e ; \
echo "Installing prettier@$(PRETTIER_VERSION)..." ; \
npm install --prefix $(LOCALBIN)/prettier-pkg prettier@$(PRETTIER_VERSION) && \
printf '#!/bin/sh\nexec node "$(LOCALBIN)/prettier-pkg/node_modules/.bin/prettier" "$$@"\n' > $(PRETTIER) && \
chmod +x $(PRETTIER) ; \
}
.PHONY: lint ## Run all linters
lint: lint-go lint-md
.PHONY: lint-md
lint-md: prettier ## Check Markdown files are formatted.
$(PRETTIER) --check '**/*.md' --ignore-path .gitignore
.PHONY: lint-go ## Lint go files.
lint-go:
golangci-lint run
.PHONY: test
test: setup-envtest
go test -v $(shell go list ./... | grep -v /examples/) -coverprofile cover.out
.PHONY: build-examples
build-examples: ## Build all example binaries.
go build ./examples/...
.PHONY: test-examples
test-examples: ## Run example tests (golden files, mutation unit tests).
go test ./examples/...
.PHONY: run-examples
run-examples: ## Run all examples to verify they execute without error.
go run ./examples/mutations-and-gating/.
go run ./examples/extraction-and-guards/.
go run ./examples/component-prerequisites/.
go run ./examples/custom-resource/.
go run ./examples/grace-inconsistency/.
##@ E2E Testing
KIND_CLUSTER_NAME ?= ocf-e2e
KIND_IMAGE ?= kindest/node:v1.31.0
.PHONY: kind-create
kind-create: ## Create a kind cluster for E2E tests (skips if it already exists).
@if kind get clusters 2>/dev/null | grep -q '^$(KIND_CLUSTER_NAME)$$'; then \
echo "Kind cluster '$(KIND_CLUSTER_NAME)' already exists, skipping creation."; \
else \
kind create cluster --name $(KIND_CLUSTER_NAME) --image $(KIND_IMAGE) --wait 60s; \
fi
.PHONY: kind-delete
kind-delete: ## Delete the kind E2E cluster.
kind delete cluster --name $(KIND_CLUSTER_NAME)
.PHONY: kind-set-context
kind-set-context: ## Set kubectl context to the E2E kind cluster.
kubectl config use-context kind-$(KIND_CLUSTER_NAME)
.PHONY: e2e
e2e: ginkgo kind-create kind-set-context ## Run all E2E tests (creates kind cluster if needed).
$(GINKGO) -v --timeout 20m --tags e2e ./e2e/...
PRIMITIVE ?=
.PHONY: e2e-primitives
e2e-primitives: ginkgo kind-create kind-set-context ## Run primitive E2E tests only. Use PRIMITIVE=<name> to filter.
$(GINKGO) -v --timeout 20m --tags e2e $(if $(PRIMITIVE),--label-filter "$(PRIMITIVE)") ./e2e/primitives/...
.PHONY: e2e-component
e2e-component: ginkgo kind-create kind-set-context ## Run component E2E tests only.
$(GINKGO) -v --timeout 15m --tags e2e ./e2e/component/...
.PHONY: e2e-full
e2e-full: kind-create kind-set-context e2e kind-delete ## Full E2E lifecycle: create cluster, test, teardown.
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef