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 4.6.2.2472
). I also added a step to install the gems I need to run unit tests and generate the report:
name: Build
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: ruby/setup-ruby@v1
with:
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
env:
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 sonar-project.properties:
sonar.projectKey=***
sonar.organization=***
# This is the name and version displayed in the SonarCloud UI.
sonar.projectName=Trackpad Tweaks
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=lib
sonar.exclusions=spec
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
# SimpleCov report
sonar.ruby.coverage.reportPaths=coverage/coverage.json
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 4.4.0.2170
. Locally, the warning disappears, and the correct coverage is reported to sonarcloud. The only difference between my sonar-project.properties
and how I call the local instance is that I’m using sonar.host.url=https://sonarcloud.io
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 !