Hello, I am facing the issue, that I want to include coverage reports of services into SonarCloud.
The coverage reports are being read, but not included, because they are apparently not in the project scope.
I do not know why they are not.
I am using GitHub Actions to run the tests and analyze using SonarScanner
This is the full workflow file:
name: Scan
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
env:
GOLANG_PROTOBUF_REGISTRATION_CONFLICT: ignore
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run golang tests
run: |
cd backend
go test -json ./... > report.json
go test -coverprofile=coverage.out ./...
cd ..
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
with:
args: >
-X
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
The sonar-project.properties
is the following:
# =====================================================
# Standard properties
# =====================================================
sonar.organization=memetoasty
sonar.projectKey=memeToasty_kioku
sonar.projectName=Go SQ-Scanner-based project
sonar.projectVersion=1.0
sonar.sources=.
sonar.exclusions=**/*_test.go,**/vendor/**
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**/vendor/**
# =====================================================
# Properties specific to Go
# =====================================================
sonar.go.tests.reportPaths=backend/report.json
sonar.go.coverage.reportPaths=backend/coverage.out
I have a test that is located in backend/services/register/handler
.
The tests run fine, the results are also correctly logged in SonarCloud, just the coverage stays at 0.0%
The logs state the following:
2023-05-07T14:42:34.8709493Z 14:42:34.870 INFO: Load coverage report from '/github/workspace/backend/coverage.out'
2023-05-07T14:42:34.8807824Z 14:42:34.880 DEBUG: Resolving file github.com/kioku-project/kioku/services/register/handler/health.go using relative path
2023-05-07T14:42:34.8814386Z 14:42:34.880 WARN: File 'github.com/kioku-project/kioku/services/register/handler/health.go' is not included in the project, ignoring coverage
2023-05-07T14:42:34.8815226Z 14:42:34.881 DEBUG: Resolving file github.com/kioku-project/kioku/services/register/handler/register.go using relative path
2023-05-07T14:42:34.8815959Z 14:42:34.881 WARN: File 'github.com/kioku-project/kioku/services/register/handler/register.go' is not included in the project, ignoring coverage
2023-05-07T14:42:34.8816487Z 14:42:34.881 INFO: Sensor Go Cover sensor for Go coverage [go] (done) | time=12ms
EDIT:
I tried to replace the github.com/kioku-project/kioku
with backend/
. THis time it seemes to include it, but it is still at 0.0% coverage.
In addition to that. The EXPLICITELY excluded file **/*_test.go
are being analyzed as source code. I am losing my nerves here