Skip to content

Commit bf51d32

Browse files
authored
DGS-16859: Run SonarQube report in pipeline (#1362)
1 parent bb108e5 commit bf51d32

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ tmp-build
77
.go-version
88
.vscode/
99
.trunk/
10+
**/*coverage.txt

.semaphore/semaphore.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ blocks:
2727
- export DYLD_LIBRARY_PATH="$HOME/confluent-kafka-go/tmp-build/lib"
2828
- rm -rf tmp-build
2929
- go install golang.org/x/lint/golint@latest && touch .do_lint
30+
- go get github.com/wadey/gocovmerge && go install github.com/wadey/gocovmerge
3031
jobs:
3132
- name: "Static Build"
3233
env_vars:
@@ -58,6 +59,7 @@ blocks:
5859
- sudo apt-get install confluent-librdkafka-plugins -y
5960
- rm -rf tmp-build
6061
- go install -v golang.org/x/lint/golint@latest && touch .do_lint
62+
- go get github.com/wadey/gocovmerge && go install github.com/wadey/gocovmerge
6163
jobs:
6264
- name: "Static Build + Integration tests (CGRP classic)"
6365
env_vars:
@@ -103,6 +105,7 @@ blocks:
103105
#- sudo apt-get install confluent-librdkafka-plugins -y
104106
- rm -rf tmp-build
105107
- go install golang.org/x/lint/golint@latest && touch .do_lint
108+
- go get github.com/wadey/gocovmerge && go install github.com/wadey/gocovmerge
106109
jobs:
107110
- name: "Static Build"
108111
env_vars:
@@ -138,3 +141,19 @@ blocks:
138141
- name: MSYSTEM
139142
value: UCRT64
140143
commands_file: semaphore_commands.ps1
144+
145+
after_pipeline:
146+
task:
147+
agent:
148+
machine:
149+
type: s1-prod-ubuntu20-04-amd64-1
150+
jobs:
151+
- name: SonarQube
152+
commands:
153+
- checkout
154+
- artifact pull workflow static_coverage.txt
155+
- artifact pull workflow dynamic_coverage.txt
156+
- artifact pull workflow static_integration_coverage.txt
157+
- artifact pull workflow dynamic_integration_coverage.txt
158+
- sem-version java 11
159+
- emit-sonarqube-data --run_only_sonar_scan

.semaphore/semaphore_commands.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
set -e
2-
if [ "$EXPECT_LINK_INFO" = "dynamic" ]; then export GO_TAGS="-tags dynamic"; bash mk/bootstrap-librdkafka.sh ${LIBRDKAFKA_VERSION} tmp-build; fi
2+
coverage_profile="static_coverage.txt"
3+
if [ "$EXPECT_LINK_INFO" = "dynamic" ]; then export GO_TAGS="-tags dynamic" && coverage_profile="dynamic_coverage.txt"; bash mk/bootstrap-librdkafka.sh ${LIBRDKAFKA_VERSION} tmp-build; fi
34
for dir in kafka examples ; do (cd $dir && go install $GO_TAGS ./...) ; done
45
if [[ -f .do_lint ]]; then golint -set_exit_status ./examples/... ./kafka/... ./kafkatest/... ./soaktest/... ./schemaregistry/...; fi
5-
for dir in kafka schemaregistry ; do (cd $dir && go test -timeout 180s -v $GO_TAGS ./...) ; done
6+
for dir in kafka schemaregistry ; do (cd $dir && go test -coverprofile="$coverage_profile" -timeout 180s -v $GO_TAGS ./...) ; done
67
go-kafkacat --help
78
library-version
89
(library-version | grep "$EXPECT_LINK_INFO") || (echo "Incorrect linkage, expected $EXPECT_LINK_INFO" ; false)
10+
11+
(gocovmerge $(find . -type f -iname "*coverage.txt") > ${coverage_profile}) || (echo "Failed to merge coverage files" && exit 0)
12+
artifact push workflow ${coverage_profile} || true

.semaphore/semaphore_integration_commands.sh

100644100755
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
set -e
2-
if [ "$EXPECT_LINK_INFO" = "dynamic" ]; then export GO_TAGS="-tags dynamic"; bash mk/bootstrap-librdkafka.sh ${LIBRDKAFKA_VERSION} tmp-build; fi
2+
coverage_profile="static_integration_coverage.txt"
3+
if [ "$EXPECT_LINK_INFO" = "dynamic" ]; then export GO_TAGS="-tags dynamic" && coverage_profile="dynamic_integration_coverage.txt"; bash mk/bootstrap-librdkafka.sh ${LIBRDKAFKA_VERSION} tmp-build; fi
34
for dir in kafka examples ; do (cd $dir && go install $GO_TAGS ./...) ; done
45
if [[ -f .do_lint ]]; then golint -set_exit_status ./examples/... ./kafka/... ./kafkatest/... ./soaktest/... ./schemaregistry/...; fi
5-
for dir in kafka schemaregistry ; do (cd $dir && go test -timeout 180s -v $GO_TAGS ./...) ; done
6+
for dir in kafka schemaregistry ; do (cd $dir && go test -coverprofile="$coverage_profile" -timeout 180s -v $GO_TAGS ./...) ; done
67
(cd kafka && go test -v $GO_TAGS -timeout 3600s -run ^TestIntegration$ -docker.needed=true ; cd ..)
78
go-kafkacat --help
89
library-version
910
(library-version | grep "$EXPECT_LINK_INFO") || (echo "Incorrect linkage, expected $EXPECT_LINK_INFO" ; false)
11+
12+
(gocovmerge $(find . -type f -iname "*coverage.txt") > ${coverage_profile}) || (echo "Failed to merge coverage files" && exit 0)
13+
artifact push workflow ${coverage_profile} || true

service.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: confluent-kafka-go
22
lang: go
3-
lang_version: 1.18
3+
lang_version: 1.21
44
git:
55
enable: true
66
github:
@@ -10,3 +10,5 @@ semaphore:
1010
enable: true
1111
sonarqube:
1212
enable: true
13+
coverage_reports:
14+
- "**/*coverage.txt"

sonar-project.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### service-bot sonarqube plugin managed file
2+
sonar.coverage.exclusions=**/test/**/*,**/tests/**/*,**/mock/**/*,**/mocks/**/*,**/*mock*,**/*test*
3+
sonar.cpd.exclusions=**/test/**/*,**/tests/**/*,**/mock/**/*,**/mocks/**/*,**/*mock*,**/*test*
4+
sonar.exclusions=**/*.pb.*,**/mk-include/**/*
5+
sonar.go.coverage.reportPaths=**/*coverage.txt
6+
sonar.language=go
7+
sonar.projectKey=confluent-kafka-go
8+
sonar.sources=.

0 commit comments

Comments
 (0)