-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathMakefile
More file actions
195 lines (173 loc) · 7.49 KB
/
Makefile
File metadata and controls
195 lines (173 loc) · 7.49 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
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: 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
.PHONY: muckrake-build-docker
muckrake-build-docker:
@echo "Building CLI binary with Docker image for Muckrake Check..."
@echo "Target: $(GOOS)/$(GOARCH)"
@echo "Clean up any possible existing containers under same name..."
@docker rm -f confluent-muckrake-builder-container 2>/dev/null || true
@echo "Building Docker image..."
docker build -f docker/Dockerfile_muckrake \
--build-arg GOOS=$(GOOS) \
--build-arg GOARCH=$(GOARCH) \
-t confluent-muckrake-builder .
@echo "Creating a container from the image..."
docker create --name confluent-muckrake-builder-container confluent-muckrake-builder
@echo "Copy built binary from the container"
docker cp confluent-muckrake-builder-container:/workspace/dist/. dist/
@echo "Clean up container"
docker rm confluent-muckrake-builder-container
@echo "✅ Binary built successfully at dist/confluent_$(GOOS)_$(GOARCH)/confluent"
.PHONY: muckrake-upload-s3
muckrake-upload-s3:
@echo "Uploading CLI binary to S3..."
@if [ -z "$(BUILD_ID)" ]; then \
echo "❌ Error: BUILD_ID is not set"; \
exit 1; \
fi
@if [ -z "$(BINARY_PATH)" ]; then \
echo "❌ Error: BINARY_PATH is not set"; \
exit 1; \
fi
@if [ -z "$(S3_KEY)" ]; then \
echo "❌ Error: S3_KEY is not set"; \
exit 1; \
fi
@if [ ! -f "$(BINARY_PATH)" ]; then \
echo "❌ Error: Binary not found at $(BINARY_PATH)"; \
exit 1; \
fi
@echo "Build ID: $(BUILD_ID)"
@echo "Binary: $(BINARY_PATH)"
@echo "S3 Key: $(S3_KEY)"
@aws s3 cp $(BINARY_PATH) s3://confluent.cloud/confluent-cli/development-builds/$(BUILD_ID)/$(S3_KEY) \
--acl public-read --region us-west-2
@echo "✅ Binary uploaded to s3://confluent.cloud/confluent-cli/development-builds/$(BUILD_ID)/$(S3_KEY)"
.PHONY: muckrake-clean
muckrake-clean:
@echo "Cleaning up Muckrake Check artifacts..."
@docker rm -f confluent-muckrake-builder-container 2>/dev/null || true
@docker rmi -f confluent-muckrake-builder 2>/dev/null || true
@echo "✅ Cleanup complete"