-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMakefile
More file actions
234 lines (204 loc) · 9.28 KB
/
Makefile
File metadata and controls
234 lines (204 loc) · 9.28 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
SHELL := /bin/bash
GORELEASER_VERSION := v2.13.3
# Compile natively based on the current system
.PHONY: build
build:
ifneq "" "$(findstring NT,$(shell uname))" # windows
CC=gcc CXX=g++ $(MAKE) cli-builder
else ifneq (,$(findstring Linux,$(shell uname)))
# Warning: make won't treat nested ifs as makefile directives if you use tabs instead of spaces
ifneq (,$(findstring musl,$(shell ldd --version))) # linux (musl)
CC=gcc CXX=g++ TAGS=musl $(MAKE) cli-builder
else # linux (glibc)
CC=gcc CXX=g++ $(MAKE) cli-builder
endif
else # darwin
$(MAKE) cli-builder
endif
# Cross-compile from darwin to any of the OS/Arch pairs below
.PHONY: cross-build
cross-build:
ifeq ($(GOARCH),arm64)
ifeq ($(GOOS),linux) # linux/arm64
CC=aarch64-linux-musl-gcc CXX=aarch64-linux-musl-g++ CGO_LDFLAGS="-static" TAGS=musl $(MAKE) cli-builder
else # darwin/arm64
$(MAKE) cli-builder
endif
else
ifeq ($(GOOS),windows) # windows/amd64
CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_LDFLAGS="-fstack-protector -static" $(MAKE) cli-builder
else ifeq ($(GOOS),linux) # linux/amd64
CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++ CGO_LDFLAGS="-static" TAGS=musl $(MAKE) cli-builder
else # darwin/amd64
$(MAKE) cli-builder
endif
endif
.PHONY: cli-builder
cli-builder:
GOOS="" GOARCH="" CC="" CXX="" CGO_LDFLAGS="" go install github.com/goreleaser/goreleaser/v2@$(GORELEASER_VERSION)
ifeq ($(GOLANG_FIPS),1)
wget "https://go.dev/dl/go$$(cat .go-version).src.tar.gz" && \
tar -xf go$$(cat .go-version).src.tar.gz && \
git clone --branch go$$(cat .go-version)-1-openssl-fips --depth 1 https://github.com/golang-fips/go.git go-openssl && \
cd go/ && \
cat ../go-openssl/patches/*.patch | patch -p1 && \
sed -i '' 's/linux/darwin/' src/crypto/internal/backend/nobackend.go && \
sed -i '' 's/linux/darwin/' src/crypto/internal/backend/openssl.go && \
sed -i '' 's/"libcrypto.so.%s"/"libcrypto.%s.dylib"/' src/crypto/internal/backend/openssl.go && \
cd src/ && \
./make.bash && \
cd ../../
PATH=$$(pwd)/go/bin:$$PATH GOROOT=$$(pwd)/go TAGS=$(TAGS) CC=$(CC) CXX=$(CXX) CGO_LDFLAGS=$(CGO_LDFLAGS) goreleaser build --clean --single-target --snapshot
rm -rf go go-openssl go$$(cat .go-version).src.tar.gz
else
TAGS=$(TAGS) CC=$(CC) CXX=$(CXX) CGO_LDFLAGS=$(CGO_LDFLAGS) goreleaser build --clean --single-target --snapshot
endif
.PHONY: clean
clean:
for dir in bin dist docs legal prebuilt release-notes; do \
[ -d $$dir ] && rm -r $$dir || true; \
done
.PHONY: lint
lint: lint-go lint-cli
.PHONY: lint-go
lint-go:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.8 && \
golangci-lint run --timeout 10m
@echo "✅ golangci-lint"
.PHONY: lint-cli
lint-cli: cmd/lint/en_US.aff cmd/lint/en_US.dic
go run cmd/lint/main.go -aff-file $(word 1,$^) -dic-file $(word 2,$^) $(ARGS)
@echo "✅ cmd/lint/main.go"
cmd/lint/en_US.aff:
curl -s "https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries/+/master/en_US.aff?format=TEXT" | base64 -D > $@
cmd/lint/en_US.dic:
curl -s "https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries/+/master/en_US.dic?format=TEXT" | base64 -D > $@
.PHONY: unit-test
unit-test:
ifdef CI
go install gotest.tools/gotestsum@v1.13.0 && \
gotestsum --junitfile unit-test-report.xml -- -timeout 0 -v -race -coverprofile=coverage.unit.out -covermode=atomic $$(go list ./... | grep -v github.com/confluentinc/cli/v4/test)
else
go test -timeout 0 -v -coverprofile=coverage.unit.out -covermode=atomic $$(go list ./... | grep -v github.com/confluentinc/cli/v4/test) $(UNIT_TEST_ARGS)
endif
.PHONY: build-for-integration-test
build-for-integration-test:
ifdef CI
go build -cover -ldflags="-s -w -X main.commit="00000000" -X main.date="1970-01-01T00:00:00Z" -X main.isTest=true" -o test/bin/confluent ./cmd/confluent
else
go build -cover -ldflags="-s -w -X main.commit="00000000" -X main.date="1970-01-01T00:00:00Z" -X main.isTest=true" -o test/bin/confluent ./cmd/confluent
endif
.PHONY: build-for-integration-test-windows
build-for-integration-test-windows:
ifdef CI
go build -cover -ldflags="-s -w -X main.commit="00000000" -X main.date="1970-01-01T00:00:00Z" -X main.isTest=true" -o test/bin/confluent.exe ./cmd/confluent
else
go build -cover -ldflags="-s -w -X main.commit="00000000" -X main.date="1970-01-01T00:00:00Z" -X main.isTest=true" -o test/bin/confluent.exe ./cmd/confluent
endif
.PHONY: integration-test
integration-test:
ifdef CI
go install gotest.tools/gotestsum@v1.13.0 && \
export GOCOVERDIR=test/coverage && \
rm -rf $${GOCOVERDIR} && mkdir $${GOCOVERDIR} && \
gotestsum --junitfile integration-test-report.xml -- -timeout 0 -v -race $$(go list ./... | grep github.com/confluentinc/cli/v4/test) && \
go tool covdata textfmt -i $${GOCOVERDIR} -o coverage.integration.out
else
export GOCOVERDIR=test/coverage && \
rm -rf $${GOCOVERDIR} && mkdir $${GOCOVERDIR} && \
go test -timeout 0 -v $$(go list ./... | grep github.com/confluentinc/cli/v4/test) $(INTEGRATION_TEST_ARGS) && \
go tool covdata textfmt -i $${GOCOVERDIR} -o coverage.integration.out
endif
.PHONY: test
test: unit-test integration-test
.PHONY: build-for-live-test
build-for-live-test:
go build -ldflags="-s -w -X main.disableUpdates=true" -o test/live/bin/confluent ./cmd/confluent
.PHONY: live-test
live-test: build-for-live-test
@if [ -z "$(CLI_LIVE_TEST_GROUPS)" ]; then \
CLI_LIVE_TEST=1 go test ./test/live/ -v -run=".*Live$$" \
-tags="live_test,all" -timeout 1440m -parallel 10; \
else \
TAGS="live_test"; \
for group in $$(echo "$(CLI_LIVE_TEST_GROUPS)" | tr ',' ' '); do \
TAGS="$$TAGS,$$group"; \
done; \
CLI_LIVE_TEST=1 go test ./test/live/ -v -run=".*Live$$" \
-tags="$$TAGS" -timeout 1440m -parallel 10; \
fi
.PHONY: live-test-core
live-test-core:
@$(MAKE) live-test CLI_LIVE_TEST_GROUPS="core"
.PHONY: live-test-kafka
live-test-kafka:
@$(MAKE) live-test CLI_LIVE_TEST_GROUPS="kafka"
.PHONY: live-test-schema-registry
live-test-schema-registry:
@$(MAKE) live-test CLI_LIVE_TEST_GROUPS="schema_registry"
.PHONY: live-test-iam
live-test-iam:
@$(MAKE) live-test CLI_LIVE_TEST_GROUPS="iam"
.PHONY: live-test-auth
live-test-auth:
@$(MAKE) live-test CLI_LIVE_TEST_GROUPS="auth"
.PHONY: live-test-connect
live-test-connect:
@$(MAKE) live-test CLI_LIVE_TEST_GROUPS="connect"
.PHONY: live-test-essential
live-test-essential:
@$(MAKE) live-test CLI_LIVE_TEST_GROUPS="core,kafka,schema_registry,auth"
.PHONY: live-test-multicloud
live-test-multicloud:
@CLI_LIVE_TEST_VARIANTS="aws:us-east-1:basic,gcp:us-east1:basic,azure:eastus:basic" \
$(MAKE) live-test CLI_LIVE_TEST_GROUPS="kafka"
.PHONY: live-test-resource
live-test-resource: build-for-live-test
@if [ -z "$(RESOURCE)" ]; then \
echo "Available resources:"; \
echo ""; \
printf " %-25s %-20s %s\n" "RESOURCE" "GROUP" "TEST FUNCTION"; \
printf " %-25s %-20s %s\n" "--------" "-----" "-------------"; \
printf " %-25s %-20s %s\n" "environment" "core" "TestEnvironmentCRUDLive"; \
printf " %-25s %-20s %s\n" "service_account" "core" "TestServiceAccountCRUDLive"; \
printf " %-25s %-20s %s\n" "api_key" "core" "TestApiKeyCRUDLive"; \
printf " %-25s %-20s %s\n" "kafka_cluster" "kafka" "TestKafkaClusterCRUDLive"; \
printf " %-25s %-20s %s\n" "kafka_topic" "kafka" "TestKafkaTopicCRUDLive"; \
printf " %-25s %-20s %s\n" "kafka_acl" "kafka" "TestKafkaACLCRUDLive"; \
printf " %-25s %-20s %s\n" "kafka_consumer_group" "kafka" "TestKafkaConsumerGroupListLive"; \
printf " %-25s %-20s %s\n" "schema_registry" "schema_registry" "TestSchemaRegistrySchemaCRUDLive"; \
printf " %-25s %-20s %s\n" "iam_rbac" "iam" "TestRBACRoleBindingCRUDLive"; \
printf " %-25s %-20s %s\n" "login" "auth" "TestLoginLogoutLive"; \
printf " %-25s %-20s %s\n" "connect" "connect" "TestConnectClusterCRUDLive"; \
echo ""; \
echo "Usage: make live-test-resource RESOURCE=<resource>"; \
else \
case "$(RESOURCE)" in \
environment) GROUP=core; FUNC=TestEnvironmentCRUDLive;; \
service_account) GROUP=core; FUNC=TestServiceAccountCRUDLive;; \
api_key) GROUP=core; FUNC=TestApiKeyCRUDLive;; \
kafka_cluster) GROUP=kafka; FUNC=TestKafkaClusterCRUDLive;; \
kafka_topic) GROUP=kafka; FUNC=TestKafkaTopicCRUDLive;; \
kafka_acl) GROUP=kafka; FUNC=TestKafkaACLCRUDLive;; \
kafka_consumer_group) GROUP=kafka; FUNC=TestKafkaConsumerGroupListLive;; \
schema_registry) GROUP=schema_registry; FUNC=TestSchemaRegistrySchemaCRUDLive;; \
iam_rbac) GROUP=iam; FUNC=TestRBACRoleBindingCRUDLive;; \
login) GROUP=auth; FUNC=TestLoginLogoutLive;; \
connect) GROUP=connect; FUNC=TestConnectClusterCRUDLive;; \
*) echo "Unknown resource: $(RESOURCE)"; echo "Run 'make live-test-resource' to see available resources."; exit 1;; \
esac; \
echo "Running $$FUNC (group: $$GROUP)..."; \
CLI_LIVE_TEST=1 go test ./test/live/ -v -run="TestLive/$$FUNC" \
-tags="live_test,$$GROUP" -timeout 1440m -parallel 10; \
fi
.PHONY: generate-packaging-patch
generate-packaging-patch:
diff -u Makefile debian/Makefile | sed "1 s_Makefile_cli/Makefile_" > debian/patches/standard_build_layout.patch
.PHONY: coverage
coverage: ## Merge coverage data from unit and integration tests into coverage.txt
@echo "Merging coverage data..."
@echo "mode: atomic" > coverage.txt
@tail -n +2 coverage.unit.out >> coverage.txt
@tail -n +2 coverage.integration.out >> coverage.txt
@echo "Coverage data saved to: coverage.txt"
@artifact push workflow coverage.txt