I’m trying to get SonarCloud to pickup the coverage file generated by go test
, but it is not coming through. Here is what is in my Bitbucket Pipeline:
options:
docker: true
size: 2x
clone:
depth: full
definitions:
services:
docker:
memory: 7142
caches:
sonar: ~/.sonar/cache
go: $GOPATH/pkg
steps:
- step: &unit-test
name: Unit Tests
size: 4x
artifacts:
- coverage.out
- report.json
image:
name: golang:1.18-buster
runs-on:
- 'mycompany.aws'
- 'self.hosted'
caches:
# cache the Ansible installation
- go
script:
- docker login https://pkg.mycompany.com/repo/mycompany-registry/v2 -u bitbucket -p "2t)rW*R&><w)@P_"
# Setting up db.
- docker run -p 3306:3306 -e "MYSQL_PASSWORD=$MYSQL_PASSWORD" -e "MYSQL_USER=bitbucket_user_test" -e "MYSQL_DATABASE=bitbucket_db_test" -e "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD" -d mysql:8.0.19
# Creating the .env
- touch .env
- echo "GRPC_SERVER_HOST=host.docker.internal" >> .env
- echo "GRPC_SERVER_PORT=9876" >> .env
- echo "DB_DSN=bitbucket_user_test:$MYSQL_PASSWORD@tcp(127.0.0.1:3306)/bitbucket_db_test?charset=utf8mb4&parseTime=True&loc=Local" >> .env
- echo "LOG_FILE_PATH=logs.txt" >> .env
- echo "SOURCE_COUNT=/apps/mycompany/bitbucket/shared/" >> .env
- echo "TARGET_MOUNT=/app/integrations/apps/" >> .env
- echo "CODE_ENGINE_IMAGE=code-engine" >> .env
- echo "DOCKER_NETWORK=mycompany" >> .env
# Running tests.
- go get
- go mod tidy
- go build
- go clean -testcache
- go test -coverprofile=coverage.out -covermode=count -v -vet=off -coverpkg=./... -gcflags=-l -json "./..." > report.json
# - go test -cover ./... -vet=off -coverpkg=./... --coverprofile=coverage.out -gcflags=-l
# - go test -cover -coverprofile=coverage.out -covermode=count -coverpkg=./... -v -vet=off -gcflags=-l -json ./... > report.json
- ls -lah .
- cat report.json
services:
- docker
- step: &sonar-scan
name: SONAR Scan
artifacts:
- report.json
runs-on:
- 'mycompany.aws'
- 'self.hosted'
caches:
- docker
- sonar
services:
- docker
script:
- echo "Code Quality Gate Scan"
- ls -lah .
- cat report.json
- pipe: sonarsource/sonarcloud-scan:1.2.2
variables:
SONAR_SCANNER_OPTS: -Xmx2040m
- step: &sonar-report
name: SONAR Report
runs-on:
- 'mycompany.aws'
- 'self.hosted'
script:
- echo "Code Quality Gate Report"
- pipe: sonarsource/sonarcloud-quality-gate:0.1.5
pipelines:
pull-requests:
'**':
- step: *unit-test
- step: *sonar-scan
- step: *sonar-report
branches:
'master':
- step: *unit-test
- step: *sonar-scan
- step: *sonar-report
The following is my sonar-project.properties file:
# -----------------------------------------------------------------------------
# Standard Properties
# -----------------------------------------------------------------------------
sonar.projectKey=mycompany_myapp-go
sonar.projectName=myapp-go
sonar.organization=mycompany
# -----------------------------------------------------------------------------
# Config about Logging
# -----------------------------------------------------------------------------
sonar.log.level=DEBUG
# -----------------------------------------------------------------------------
# Config for Source Information
# -----------------------------------------------------------------------------
sonar.sources=./mapp
sonar.exclusions=**/*_test.go,**/vendor/**
# -----------------------------------------------------------------------------
# Config for Testing
# -----------------------------------------------------------------------------
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**/vendor/**
# -----------------------------------------------------------------------------
# Config for Go
# -----------------------------------------------------------------------------
sonar.go.golint.reportPaths=./coverage.out
sonar.go.coverage.reportPaths=./report.json
I’m really not sure why SonarCloud is not picking up my coverage report.