Sonarcloud ruby Coverage not working

Hi, I am trying to get the coverage working for a Ruby/Rails project that uses rspec. We are using:
simplecov (0.21.2)
simplecov_json_formatter (0.1.2)
Our rspec run creates the coverage/coverage.json file.

When sonar scans the overage I get the error:

WARN: File ‘/home/github/actions-runner/_work/mediascape_integration/mediascape_integration/app/models/media_type.rb’ is present in coverage report but cannot be found in filesystem

That is the fully qualified path on the github runner, the same runner is used for the sonarcloud scan.
I have tried to change the path to a relative path but it still fails.

File ‘app/models/api/mediascape_tenant_advertiser.rb’ is present in coverage report but cannot be found in filesystem

Our coverage reported in sonarcloud is 0%.

What path is sonarcloud expecting?

Welcome to the community!

I believe it is expecting relative paths from the working directory in which the scanner is executed, which should be the project root. It seems to me the working directory in your setup should be /home/github/actions-runner/_work/mediascape_integration/mediascape_integration, so relative paths from that would be expected, such as app/models/media_type.rb.

I notice that your absolute path and relative path examples refer to different files:

  • /home/github/actions-runner/_work/mediascape_integration/mediascape_integration/app/models/media_type.rb
  • app/models/api/mediascape_tenant_advertiser.rb

The second path format looks good, in that it looks like a relative path in your project. But does this file actually exist at the time your analysis runs?

Yes that file does exist in the relative path. I mistakenly pasted a different file in the example, both are correct. We still cannot get coverage results, we continue to get the warning for each file…

WARN: File ‘app/models/api/mediascape_tenant_advertiser.rb’ is present in coverage report but cannot be found in filesystem

Ok it seems I got that completely wrong. Looking at our code, absolute paths are explicitly supported, so that’s what you should use.

In your initial post, you were correctly using absolute paths. But according to the warning, it seems the file /home/github/actions-runner/_work/mediascape_integration/mediascape_integration/app/models/media_type.rb simply isn’t there in the filesystem. Can you please add this command line before executing the scanner to verify if it really exists or not:

ls -l /home/github/actions-runner/_work/mediascape_integration/mediascape_integration/app/models/media_type.rb

It does find the file…

ls -l /home/github/actions-runner/_work/mediascape_integration/mediascape_integration/app/models/media_type.rb

3 shell: /bin/bash -e {0}

4-rw-r–r-- 1 github github 77 Apr 14 19:55 /home/github/actions-runner/_work/mediascape_integration/mediascape_integration/app/models/media_type.rb

Can you please share the following:

  • all the scanner parameters used by the analysis (most interesting are sonar.sources , sonar.inclusions , sonar.exclusions, but others may be relevant too)
  • the complete scanner output

Probably it occurs only on github actions.

Have not investigated exacly why github actions dont understand paths from simplecov report, but i managed to fix it with separete step.

- name: fix code coverage paths
        working-directory: ./coverage
        run: |
          sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' .resultset.json
2 Likes