Welcome to mirror list, hosted at ThFree Co, Russian Federation.

simplecov.rake « ci « tasks « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0c8322940ec952bfba167ea714008fb4bfe528ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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