CI system used: Gitlab
Scanner command
sonar-scanner -X
Languages of the repository
- Ruby
Error observed
...
...
12:45:22.395 INFO: Sensor SimpleCov Sensor for Ruby coverage [ruby]
12:45:22.559 WARN: Importing SimpleCov resultset JSON will not be supported from simplecov 18.0.
...
...
12:44:58.975 DEBUG: 'app/models/product_target.rb' indexed with language 'ruby'
...
...
...
12:45:22.630 WARN: File 'app/models/product_target.rb' is present in coverage report but cannot be found in filesystem
...
...
As a result, the coverage analysis indicates 0% coverage.
Steps to reproduce
- Setup a Ruby on Rails project using the following gems for the coverage report:
gem 'simplecov', '~> 0.17.1', require: false
gem 'simplecov-json', require: false
adding to your test helper file:
require 'simplecov'
require 'simplecov-json'
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
SimpleCov.start 'rails'
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=app/
sonar.exclusions=app/assets/**/*
sonar.tests=test/
#sonar.test.inclusions=
# Test coverage
#sonar.coverage.exclusions=
# SimpleCov report
sonar.ruby.coverage.reportPaths=./coverage/.resultset.json
ms2_test:
stage: test
...
script:
- bundle exec rake db:create db:schema:load
- bundle exec rails test -d -b
after_script:
- sed -i 's@'"$CI_PROJECT_DIR"'/@@g' coverage/coverage.json
artifacts:
when: always
expire_in: 30 min
paths:
- coverage
sonarcloud-check:
stage: analyze
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
cache:
key: "${CI_COMMIT_SHORT_SHA}"
paths:
- .sonar/cache
dependencies:
- ms2_test
script:
- sonar-scanner -X
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_REF_PROTECTED == "true"
Potential workarounds
- Replacing the absolute paths in the coverage file using sed -inspired on the solution used with Github- does not solve the issue.