Skip to content

Commit 1196f86

Browse files
authored
SonarQube integration for CLI w/o Service Bot (#3084)
1 parent ccd7d61 commit 1196f86

File tree

3 files changed

+71
-39
lines changed

3 files changed

+71
-39
lines changed

.semaphore/semaphore.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ blocks:
2020
- name: "Test linux/amd64"
2121
commands:
2222
- checkout
23+
- . vault-sem-get-secret v1/ci/kv/apif/cli/sonar_token
2324
- sem-version go $(cat .go-version)
2425
- export PATH=$(go env GOPATH)/bin:$PATH
2526
- make generate-packaging-patch
2627
- diff -w -u <(git cat-file --filters HEAD:debian/patches/standard_build_layout.patch | awk "{if (NR>3) {print}}") <(cat debian/patches/standard_build_layout.patch | awk "{if (NR>3) {print}}")
2728
- make lint
2829
- make test
30+
- make coverage
2931
- make test-installer
3032
# Temporarily disable these builds until rate limiting is resolved
3133
# - name: "Build linux/amd64 (GLIBC)"
@@ -122,3 +124,8 @@ after_pipeline:
122124
- name: Publish Results
123125
commands:
124126
- test-results gen-pipeline-report
127+
- name: Report SonarQube Results
128+
commands:
129+
- checkout
130+
- sem-version java 11
131+
- emit-sonarqube-data -a coverage.txt

Makefile

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,25 @@ cmd/lint/en_US.dic:
9898
unit-test:
9999
ifdef CI
100100
go install gotest.tools/gotestsum@v1.12.1 && \
101-
gotestsum --junitfile unit-test-report.xml -- -timeout 0 -v -race -coverprofile coverage.out $$(go list ./... | grep -v github.com/confluentinc/cli/v4/test)
101+
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)
102102
else
103-
go test -timeout 0 -v $$(go list ./... | grep -v github.com/confluentinc/cli/v4/test) $(UNIT_TEST_ARGS)
103+
go test -timeout 0 -v -coverprofile=coverage.unit.out -covermode=atomic $$(go list ./... | grep -v github.com/confluentinc/cli/v4/test) $(UNIT_TEST_ARGS)
104104
endif
105105

106106
.PHONY: build-for-integration-test
107107
build-for-integration-test:
108108
ifdef CI
109109
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
110110
else
111-
go build -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
111+
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
112112
endif
113113

114114
.PHONY: build-for-integration-test-windows
115115
build-for-integration-test-windows:
116116
ifdef CI
117117
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
118118
else
119-
go build -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
119+
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
120120
endif
121121

122122
.PHONY: integration-test
@@ -126,9 +126,12 @@ ifdef CI
126126
export GOCOVERDIR=test/coverage && \
127127
rm -rf $${GOCOVERDIR} && mkdir $${GOCOVERDIR} && \
128128
gotestsum --junitfile integration-test-report.xml -- -timeout 0 -v -race $$(go list ./... | grep github.com/confluentinc/cli/v4/test) && \
129-
go tool covdata textfmt -i $${GOCOVERDIR} -o test/coverage.out
129+
go tool covdata textfmt -i $${GOCOVERDIR} -o coverage.integration.out
130130
else
131-
go test -timeout 0 -v $$(go list ./... | grep github.com/confluentinc/cli/v4/test) $(INTEGRATION_TEST_ARGS)
131+
export GOCOVERDIR=test/coverage && \
132+
rm -rf $${GOCOVERDIR} && mkdir $${GOCOVERDIR} && \
133+
go test -timeout 0 -v $$(go list ./... | grep github.com/confluentinc/cli/v4/test) $(INTEGRATION_TEST_ARGS) && \
134+
go tool covdata textfmt -i $${GOCOVERDIR} -o coverage.integration.out
132135
endif
133136

134137
.PHONY: test
@@ -137,3 +140,12 @@ test: unit-test integration-test
137140
.PHONY: generate-packaging-patch
138141
generate-packaging-patch:
139142
diff -u Makefile debian/Makefile | sed "1 s_Makefile_cli/Makefile_" > debian/patches/standard_build_layout.patch
143+
144+
.PHONY: coverage
145+
coverage: ## Merge coverage data from unit and integration tests into coverage.txt
146+
@echo "Merging coverage data..."
147+
@echo "mode: atomic" > coverage.txt
148+
@tail -n +2 coverage.unit.out >> coverage.txt
149+
@tail -n +2 coverage.integration.out >> coverage.txt
150+
@echo "Coverage data saved to: coverage.txt"
151+
@artifact push workflow coverage.txt

debian/patches/standard_build_layout.patch

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
--- cli/Makefile 2025-04-08 14:28:12.578002798 -0700
2-
+++ debian/Makefile 2025-04-08 08:10:32.221837084 -0700
3-
@@ -1,139 +1,163 @@
1+
--- cli/Makefile 2025-04-24 16:07:56.961999373 -0500
2+
+++ debian/Makefile 2025-02-12 09:00:49.891230440 -0600
3+
@@ -1,151 +1,163 @@
44
-SHELL := /bin/bash
55
-GORELEASER_VERSION := v1.21.2
66
+SHELL=/bin/bash
@@ -146,16 +146,18 @@
146146
+ filepath=windows_amd64/confluent.exe; \
147147
+ curl -fs https://$${baseurl}/confluent-cli/binaries/$(CLI_VERSION)/confluent$${version}_windows_amd64.exe -o $${filepath}; \
148148
+ chmod 755 $${filepath}
149+
+
150+
+ cp LICENSE $(DESTDIR)$(DOCPATH)/COPYRIGHT
151+
+ $(DESTDIR)$(BINPATH)/confluent --version | awk -F' ' '{ print $3 }' > $(DESTDIR)$(DOCPATH)/version.txt
149152

150153
-S3_DEB_RPM_BUCKET_NAME=confluent-cli-release
151154
-S3_DEB_RPM_PROD_PREFIX=confluent-cli
152155
-S3_DEB_RPM_PROD_PATH=s3://$(S3_DEB_RPM_BUCKET_NAME)/$(S3_DEB_RPM_PROD_PREFIX)
153156
-S3_DEB_RPM_STAG_PATH=s3://$(S3_DEB_RPM_BUCKET_NAME)/confluent-cli-staging
154-
+ cp LICENSE $(DESTDIR)$(DOCPATH)/COPYRIGHT
155-
+ $(DESTDIR)$(BINPATH)/confluent --version | awk -F' ' '{ print $3 }' > $(DESTDIR)$(DOCPATH)/version.txt
157+
+ chown -R root:root $(DESTDIR)$(PREFIX)
156158

157159
-.PHONY: clean
158-
-clean:
160+
clean:
159161
- for dir in bin dist docs legal prebuilt release-notes; do \
160162
- [ -d $$dir ] && rm -r $$dir || true; \
161163
- done
@@ -184,28 +186,10 @@
184186
-unit-test:
185187
-ifdef CI
186188
- go install gotest.tools/gotestsum@v1.12.1 && \
187-
- gotestsum --junitfile unit-test-report.xml -- -timeout 0 -v -race -coverprofile coverage.out $$(go list ./... | grep -v github.com/confluentinc/cli/v4/test)
189+
- 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)
188190
-else
189-
- go test -timeout 0 -v $$(go list ./... | grep -v github.com/confluentinc/cli/v4/test) $(UNIT_TEST_ARGS)
191+
- go test -timeout 0 -v -coverprofile=coverage.unit.out -covermode=atomic $$(go list ./... | grep -v github.com/confluentinc/cli/v4/test) $(UNIT_TEST_ARGS)
190192
-endif
191-
+ chown -R root:root $(DESTDIR)$(PREFIX)
192-
193-
-.PHONY: build-for-integration-test
194-
-build-for-integration-test:
195-
-ifdef CI
196-
- 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
197-
-else
198-
- go build -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
199-
-endif
200-
-
201-
-.PHONY: build-for-integration-test-windows
202-
-build-for-integration-test-windows:
203-
-ifdef CI
204-
- 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
205-
-else
206-
- go build -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
207-
-endif
208-
+clean:
209193
+ rm -rf $(CURDIR)/$(PACKAGE_NAME)*
210194
+ rm -rf $(FULL_PACKAGE_TITLE)-$(RPM_VERSION)*rpm
211195
+ rm -rf RPM_BUILDING
@@ -271,26 +255,55 @@
271255
+ rm -f $@ && tar -czf RPM_BUILDING/SOURCES/$(FULL_PACKAGE_TITLE)-$(RPM_VERSION).tar.gz $(FULL_PACKAGE_TITLE)-$(RPM_VERSION)
272256
+ rm -rf $(FULL_PACKAGE_TITLE)-$(RPM_VERSION)
273257

258+
-.PHONY: build-for-integration-test
259+
-build-for-integration-test:
260+
-ifdef CI
261+
- 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
262+
-else
263+
- 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
264+
-endif
265+
+rpm-build-area: RPM_BUILDING/BUILD RPM_BUILDING/RPMS RPM_BUILDING/SOURCES RPM_BUILDING/SPECS RPM_BUILDING/SRPMS
266+
267+
-.PHONY: build-for-integration-test-windows
268+
-build-for-integration-test-windows:
269+
-ifdef CI
270+
- 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
271+
-else
272+
- 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
273+
-endif
274+
+RPM_BUILDING/%:
275+
+ mkdir -p $@
276+
274277
-.PHONY: integration-test
275278
-integration-test:
276279
-ifdef CI
277280
- go install gotest.tools/gotestsum@v1.12.1 && \
278281
- export GOCOVERDIR=test/coverage && \
279282
- rm -rf $${GOCOVERDIR} && mkdir $${GOCOVERDIR} && \
280283
- gotestsum --junitfile integration-test-report.xml -- -timeout 0 -v -race $$(go list ./... | grep github.com/confluentinc/cli/v4/test) && \
281-
- go tool covdata textfmt -i $${GOCOVERDIR} -o test/coverage.out
284+
- go tool covdata textfmt -i $${GOCOVERDIR} -o coverage.integration.out
282285
-else
283-
- go test -timeout 0 -v $$(go list ./... | grep github.com/confluentinc/cli/v4/test) $(INTEGRATION_TEST_ARGS)
286+
- export GOCOVERDIR=test/coverage && \
287+
- rm -rf $${GOCOVERDIR} && mkdir $${GOCOVERDIR} && \
288+
- go test -timeout 0 -v $$(go list ./... | grep github.com/confluentinc/cli/v4/test) $(INTEGRATION_TEST_ARGS) && \
289+
- go tool covdata textfmt -i $${GOCOVERDIR} -o coverage.integration.out
284290
-endif
285-
+rpm-build-area: RPM_BUILDING/BUILD RPM_BUILDING/RPMS RPM_BUILDING/SOURCES RPM_BUILDING/SPECS RPM_BUILDING/SRPMS
286-
291+
-
287292
-.PHONY: test
288293
-test: unit-test integration-test
289-
+RPM_BUILDING/%:
290-
+ mkdir -p $@
291-
294+
-
292295
-.PHONY: generate-packaging-patch
293296
-generate-packaging-patch:
294297
- diff -u Makefile debian/Makefile | sed "1 s_Makefile_cli/Makefile_" > debian/patches/standard_build_layout.patch
298+
-
299+
-.PHONY: coverage
300+
-coverage: ## Merge coverage data from unit and integration tests into coverage.txt
301+
- @echo "Merging coverage data..."
302+
- @echo "mode: atomic" > coverage.txt
303+
- @tail -n +2 coverage.unit.out >> coverage.txt
304+
- @tail -n +2 coverage.integration.out >> coverage.txt
305+
- @echo "Coverage data saved to: coverage.txt"
306+
- @artifact push workflow coverage.txt
307+
\ No newline at end of file
295308
+RELEASE_%:
296309
+ echo 0 > $@

0 commit comments

Comments
 (0)