summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-06-30 16:08:01 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-07-21 12:44:24 +0200
commitbd709e29b50940409d6b1abc869fe2969d6a3b51 (patch)
treefc5caa0802672ac2b206971bc6a0203b40b75728
parent647da42af99a703fc3af3452b39acf0c3dc3050d (diff)
downloadgitlab-ce-bd709e29b50940409d6b1abc869fe2969d6a3b51.tar.gz
Use `scripts/merge-simplecov`
-rw-r--r--.gitlab-ci.yml2
-rw-r--r--lib/tasks/ci/simplecov.rake63
-rwxr-xr-xscripts/merge-simplecov65
3 files changed, 66 insertions, 64 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b0010572833..9a90c99a996 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -65,7 +65,7 @@ update-coverage:
<<: *knapsack-state
stage: post-test
script:
- - bundle exec rake ci:simplecov:merge
+ - bundle exec scripts/merge-simplecov
artifacts:
paths:
- coverage/
diff --git a/lib/tasks/ci/simplecov.rake b/lib/tasks/ci/simplecov.rake
deleted file mode 100644
index 0c8322940ec..00000000000
--- a/lib/tasks/ci/simplecov.rake
+++ /dev/null
@@ -1,63 +0,0 @@
-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
diff --git a/scripts/merge-simplecov b/scripts/merge-simplecov
new file mode 100755
index 00000000000..b59ff0ae9a0
--- /dev/null
+++ b/scripts/merge-simplecov
@@ -0,0 +1,65 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path('../spring', __FILE__)
+rescue LoadError => e
+ raise unless e.message.include?('spring')
+end
+
+require 'simplecov'
+
+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
+
+SimpleCov.configure do
+ merge_timeout 7200
+end
+
+merged_result.format!