Sha256: 67cbe6789fa2871128a346ad8af2d31a3bb0cc09269f2745827eb8adfb839970

Contents?: true

Size: 978 Bytes

Versions: 64

Compression:

Stored size: 978 Bytes

Contents

# frozen_string_literal: true

require "json"
require "pathname"

# The coverage data in resultset.json from SimpleCov contains absolute file paths
# As that can confuse the sonarcloud sonar-scanner if it's running in a Docker for example
# In the block below we are transforming the absolute file paths to relative paths
puts "Transforming coverage/.resultset.json to sonar-scanner valid format in coverage/.resultset.sonar.json"
json = JSON.parse(File.read("coverage/.resultset.json"))
puts "Fixing file paths…"
json["RSpec"]["coverage"].transform_keys! do |file|
  path = Pathname.new(file).relative_path_from(Pathname.new(File.expand_path("."))).to_s
  path.slice! ".."
  path if ENV["CI"].nil?

  "/github/workspace/#{path}"
end
puts "Fixing json line information…"
json["RSpec"]["coverage"].transform_values! do |value|
  value["lines"]
end
File.write("coverage/.resultset.sonar.json", JSON.dump(json))
puts "Wrote new coverage json to coverage/.resultset.sonar.json"

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
ci_toolkit-1.6.4 transform_coverage_data.rb
ci_toolkit-1.6.3 transform_coverage_data.rb
ci_toolkit-1.6.2 transform_coverage_data.rb
ci_toolkit-1.6.1 transform_coverage_data.rb
ci_toolkit-1.6.0 transform_coverage_data.rb
ci_toolkit-1.5.24 transform_coverage_data.rb
ci_toolkit-1.5.23 transform_coverage_data.rb
ci_toolkit-1.5.22 transform_coverage_data.rb
ci_toolkit-1.5.21 transform_coverage_data.rb
ci_toolkit-1.5.20 transform_coverage_data.rb
ci_toolkit-1.5.19 transform_coverage_data.rb
ci_toolkit-1.5.17 transform_coverage_data.rb
ci_toolkit-1.5.16 transform_coverage_data.rb
ci_toolkit-1.5.15 transform_coverage_data.rb
ci_toolkit-1.5.14 transform_coverage_data.rb
ci_toolkit-1.5.13 transform_coverage_data.rb
ci_toolkit-1.5.12 transform_coverage_data.rb
ci_toolkit-1.5.11 transform_coverage_data.rb
ci_toolkit-1.5.10 transform_coverage_data.rb
ci_toolkit-1.5.9 transform_coverage_data.rb