diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-06-30 16:44:29 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-07-21 13:44:24 +0300 |
commit | 647da42af99a703fc3af3452b39acf0c3dc3050d (patch) | |
tree | 72f2b964b4a6e486cc63e23bd56ca676fbd7dc0f /lib/tasks | |
parent | ef30678f1bab04b0f07a60e57966e3eed17c6842 (diff) |
Merge coverage report
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/ci/simplecov.rake | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/tasks/ci/simplecov.rake b/lib/tasks/ci/simplecov.rake new file mode 100644 index 00000000000..0c8322940ec --- /dev/null +++ b/lib/tasks/ci/simplecov.rake @@ -0,0 +1,63 @@ +require 'simplecov' + +namespace :ci do + namespace :simplecov do + desc 'GitLab CI | Merge all coverage results and generate report' + task merge: :environment do + merged_result.format! + end + + private + + def read(file) + return unless File.exist?(file) + data = File.read(file) + return if data.nil? || data.length < 2 + data + end + + def load(file) + begin + JSON.parse(read(file)) + rescue + {} + end + end + + def files + Dir.glob(File.join(SimpleCov.coverage_path, '*/.resultset.json')) + end + + def resultsfiles + files.map { |file| load(file) } + end + + def resultsets + resultsfiles.reduce({}, :merge) + end + + def all_results + results = [] + resultsets.each do |command_name, data| + result = SimpleCov::Result.from_hash(command_name => data) + # Only add result if the timeout is above the configured threshold + if (Time.now - result.created_at) < SimpleCov.merge_timeout + results << result + end + end + results + end + + def merged_result + merged = {} + results = all_results + results.each do |result| + merged = result.original_result.merge_resultset(merged) + end + result = SimpleCov::Result.new(merged) + # Specify the command name + result.command_name = results.map(&:command_name).sort.join(", ") + result + end + end +end |