Github Actions / Sonarqube / SimpleCov

Hello everyone,

I’m starting a Ruby project and I’d like sonar to use the code coverage report generated by SimpleCov. I’m using version 0.21.2

I’d like to automate this, so I’m using this Github Actions template provided by the sonar doc (version showed in the logs: SonarScanner I also added a step to install the gems I need to run unit tests and generate the report:

name: Build
      - main
    types: [opened, synchronize, reopened]
    name: SonarCloud
    runs-on: ubuntu-latest
      - uses: actions/checkout@v2
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
      - uses: ruby/setup-ruby@v1
          ruby-version: 2.5.8
          bundler-cache: true
      - name: Unit tests and coverage report
        run: bundle exec rspec --format doc
      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@master
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

I also added the SONAR_SECRET variable to my repo. This is my


# This is the name and version displayed in the SonarCloud UI.
sonar.projectName=Trackpad Tweaks

# Path is relative to the file. Replace "\" by "/" on Windows.

# Encoding of the source code. Default is default system encoding

# SimpleCov report

When Github Actions runs, it completes successfully but I can see in the logs WARN: File '/home/runner/work/TT/TT/lib/event_queue.rb' is present in coverage report but cannot be found in filesystem

It then displays on the Sonarcloud overview 0% coverage.

I couldn’t figure this out so I tried to run the scan myself. I’m using SonarScanner Locally, the warning disappears, and the correct coverage is reported to sonarcloud. The only difference between my and how I call the local instance is that I’m using and sonar.login=*** otherwise it fails. So I believe there is something to do as it works locally. I just would like to automate this step.

I’m kinda stuck right now, I’ve been reading a lot of similar issues between SimpleCov and SonarScan but I couldn’t find a fix. Any help would be appreciated. Thanks for reading !

Bumping ; I still didn’t find a solution.

Hello @Chocorean , seems to me your problem is related to the report paths. Could you take a look on this similar case (more specific this one) and see if that helps you?

Hello @Chocorean

I faced the same issue with reporting code-coverage from Github Actions to SonarCloud and found the following solution:

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

Add this step after running RSpec and before the sonarcloud analysis. It will fix paths in coverage.json and code-coverage will be reported successfully.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.