SonarScanner does not include file in subpath in scan

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

Hey there.

Based on this job:

It looks like you sorted it out. Is that correct?

I mean kind of, but not really, because this solution forces me to have 2 seperate projects for one repository. Is there another way to solve this?

Because I still want to utilize static code analysis for the frontend for example and it would be neat to have both in one project

Hey there.

How did having two separate projects help here?

It helped, because I have to execute my golang tests from the backend folder instead of the project root folder, because the root folder is not a go module.
When SonarScanner executed from the root folder it always reported that the covered files where not part of the project.