Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplecov update #91

Merged
merged 3 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ return unless ENV["COVERAGE"] && !ENV["COV_MERGE"]
SimpleCov.start do
add_filter ["/spec/", "/fixture/", "/features/"]
minimum_coverage 95
enable_coverage :branch
formatter SimpleCov::Formatter::SimpleFormatter
end
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ group :test do
gem "rspec", "~> 3.9.0"
gem "rubocop", "~> 0.80.0"
gem "rubocop-performance", "~> 1.5.2"
gem "simplecov", "~> 0.17.1"
gem "simplecov", "~> 0.18.5"
gem "simplecov-console", "~> 0.6.0"
end
19 changes: 9 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ GEM
ansi (1.5.0)
ast (2.4.0)
backport (1.1.2)
backports (3.15.0)
backports (3.16.1)
benchmark (0.1.0)
builder (3.2.4)
coderay (1.1.2)
Expand Down Expand Up @@ -84,15 +84,15 @@ GEM
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.0)
rspec-support (~> 3.9.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-expectations (3.9.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.0)
rspec-support (3.9.2)
rubocop (0.80.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
Expand All @@ -106,15 +106,14 @@ GEM
ruby-progressbar (1.10.1)
ruby2_keywords (0.0.2)
semantic (1.6.1)
simplecov (0.17.1)
simplecov (0.18.5)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (~> 0.11)
simplecov-console (0.6.0)
ansi
simplecov
terminal-table
simplecov-html (0.10.2)
simplecov-html (0.12.1)
solargraph (0.38.5)
backport (~> 1.1)
benchmark
Expand Down Expand Up @@ -155,7 +154,7 @@ DEPENDENCIES
rubocop (~> 0.80.0)
rubocop-performance (~> 1.5.2)
semantic (~> 1.6.1)
simplecov (~> 0.17.1)
simplecov (~> 0.18.5)
simplecov-console (~> 0.6.0)
solargraph (~> 0.38.5)

Expand Down
20 changes: 12 additions & 8 deletions lib/task_helpers/cc_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
class CodeClimateUploader
CC_REPORTER_URL = "https://codeclimate.com/downloads/test-reporter/test-reporter-0.6.3-linux-amd64"
CC_REPORTER = "vendor/bundle/cc_reporter_0.6.3"
CC_JSON = "codeclimate.json"
SIMPLECOV_RESULT = "coverage/.resultset.json"
CC_JSON = "coverage/codeclimate.json"

class << self
def upload
def upload(simplecov_result)
download_reporter
format_coverage
format_coverage(simplecov_result)
upload_coverage
end

private

def format_coverage
system(cc_env, "./#{CC_REPORTER} format-coverage #{SIMPLECOV_RESULT} -t simplecov -o #{CC_JSON}")
def format_coverage(simplecov_result)
shell("./#{CC_REPORTER} format-coverage #{simplecov_result} -t simplecov -o #{CC_JSON}", cc_env)
end

def upload_coverage
system(cc_env, "./#{CC_REPORTER} upload-coverage -i #{CC_JSON}")
shell("./#{CC_REPORTER} upload-coverage -i #{CC_JSON}", cc_env)
end

def cc_env
Expand All @@ -42,7 +41,12 @@ def pull_request?
def download_reporter
return if File.exist?(CC_REPORTER)

system("curl -s -L #{CC_REPORTER_URL} -o #{CC_REPORTER} && chmod a+x #{CC_REPORTER}")
shell("curl -s -L #{CC_REPORTER_URL} -o #{CC_REPORTER} && chmod a+x #{CC_REPORTER}")
end

def shell(cmd, env = {})
status = system(env, cmd)
raise StandardError.new("Command failed") unless status
end
end
end
33 changes: 21 additions & 12 deletions lib/task_helpers/simplecov_merger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,40 @@ class SimpleCovMerger
extend TaskUtil

class << self
def merge_coverage
def merge_coverage(cc_resultset_json)
ENV["COV_MERGE"] = "true"
require "simplecov"
require "simplecov-console"

SimpleCov.configure do
%w[allure-cucumber allure-rspec allure-ruby-commons].each { |g| add_group(g, g) }
formatter(multiformatter)
minimum_coverage(95)
end

merge_results
generate_cc_resultset(cc_resultset_json)
end

private

def merge_results
puts "Generating combined coverage report".yellow
results = Dir.glob("#{root}/*/coverage/.resultset.json").each_with_object([]) do |file, res|
res << SimpleCov::Result.from_hash(JSON.parse(File.read(file)))
groups.each { |g| SimpleCov.add_group(g, g) }
SimpleCov.collate(Dir["#{root}/*/coverage/.resultset.json"]) do
formatter(multiformatter)
minimum_coverage(95)
enable_coverage(:branch)
end
SimpleCov::ResultMerger.merge_results(*results).tap do |result|
SimpleCov::ResultMerger.store_result(result)
result.format!
end

def generate_cc_resultset(cc_resultset_json)
resultset = JSON.parse(File.read("#{root}/coverage/.resultset.json"))
primary_key = groups.join(", ")

cc_resultset = resultset[primary_key]["coverage"].each_with_object({}) do |(k, v), h|
h[k] = v["lines"]
end

File.write(cc_resultset_json, { primary_key => { "coverage" => cc_resultset } }.to_json, mode: "w")
end

def groups
@groups ||= %w[allure-cucumber allure-rspec allure-ruby-commons]
end

def multiformatter
Expand Down
5 changes: 3 additions & 2 deletions lib/tasks/test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class TestTasks
ENV["COVERAGE"] = "true"
run_all_adaptors(:test)
ensure
SimpleCovMerger.merge_coverage
CodeClimateUploader.upload if ENV["CI"] && ENV["RUBY_VERSION"] == "2.7"
cc_resultset_json = "coverage/.resultset_cc.json"
SimpleCovMerger.merge_coverage(cc_resultset_json)
CodeClimateUploader.upload(cc_resultset_json) if ENV["CI"] && ENV["RUBY_VERSION"] == "2.7"
end
end
end
Expand Down