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.4.1 transform_coverage_data.rb
ci_toolkit-1.4.0 transform_coverage_data.rb
ci_toolkit-1.3.21 transform_coverage_data.rb
ci_toolkit-1.3.20 transform_coverage_data.rb
ci_toolkit-1.3.18 transform_coverage_data.rb
ci_toolkit-1.3.17 transform_coverage_data.rb
ci_toolkit-1.3.16 transform_coverage_data.rb
ci_toolkit-1.3.15 transform_coverage_data.rb
ci_toolkit-1.3.14 transform_coverage_data.rb
ci_toolkit-1.3.13 transform_coverage_data.rb
ci_toolkit-1.3.12 transform_coverage_data.rb
ci_toolkit-1.3.10 transform_coverage_data.rb
ci_toolkit-1.3.9 transform_coverage_data.rb
ci_toolkit-1.3.8 transform_coverage_data.rb
ci_toolkit-1.3.6 transform_coverage_data.rb
ci_toolkit-1.2.9 transform_coverage_data.rb
ci_toolkit-1.2.8 transform_coverage_data.rb
ci_toolkit-1.2.7 transform_coverage_data.rb
ci_toolkit-1.2.6 transform_coverage_data.rb
ci_toolkit-1.2.5 transform_coverage_data.rb