Skip to content

Instantly share code, notes, and snippets.

@grodowski
Last active September 26, 2022 04:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grodowski/9744ff91034dce8df20c2a8210409fb0 to your computer and use it in GitHub Desktop.
Save grodowski/9744ff91034dce8df20c2a8210409fb0 to your computer and use it in GitHub Desktop.
Merge coverage reports from parallel circle test containers
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'simplecov'
require 'simplecov-lcov'
puts('Merging coverage results from parallel CircleCI tests containers into a single LCOV report...')
results = []
Dir['/home/circleci/rspec/*.resultset.json'].each do |path|
resultset = JSON.parse(File.read(path))
resultset.each do |_, data|
cmd = File.basename(path)
results << SimpleCov::Result.from_hash(cmd => data)
end
print '.'
end
puts
merged_result = SimpleCov::ResultMerger.merge_results(*results)
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
SimpleCov::Formatter::LcovFormatter.config.single_report_path = ARGV[0] || 'coverage.lcov'
SimpleCov::Formatter::LcovFormatter.new.format(merged_result)
puts("Done! LCOV saved to #{SimpleCov::Formatter::LcovFormatter.config.single_report_path}")
@eguchi-ken
Copy link

eguchi-ken commented Sep 26, 2022

The above script is outdated.
The following script was substituted.

      require 'simplecov'
      require 'simplecov-lcov'

      path_string = '/home/circleci/rspec/*.resultset.json'
      out_file_name = 'coverage.lcov'

      puts('Merging coverage results into a single LCOV report...')

      SimpleCov::Formatter::LcovFormatter.config.lcov_file_name = out_file_name
      SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
      SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
      SimpleCov.collate(Dir[path_string])

      puts("Done!")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment