Skip to content

Commit

Permalink
Merge pull request #14141 from hennevogel/update/test-coverage
Browse files Browse the repository at this point in the history
Renovate Coverage Report Generation & Upload
  • Loading branch information
hennevogel committed Apr 14, 2023
2 parents da1ff05 + 7d1fbe1 commit 5e85efa
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 112 deletions.
25 changes: 20 additions & 5 deletions .circleci/conditional_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ jobs:
root: .
paths:
- .

linters:
docker:
- <<: *frontend_base
Expand Down Expand Up @@ -264,7 +265,6 @@ jobs:
- run:
name: Run minitest
environment:
DO_COVERAGE: 1
TESTOPTS: "--ci-dir=/home/frontend/minitest"
working_directory: src/api
command: |
Expand Down Expand Up @@ -368,16 +368,31 @@ jobs:
- attach_workspace:
at: .
- run:
name: Merge and check coverage
name: Merge coverage
working_directory: src/api
command: bundle exec rake ci:simplecov_ci_merge
- run:
name: Upload coverage to codecov
working_directory: src/api
command: |
export COVERALLS_REPO_TOKEN=HWLJwfiFsKPGEOzfgllO3pP3rqV540Qt3
bundle exec rake ci:simplecov_ci_merge
curl -LOs https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -v -f coverage/coverage.xml
- run:
name: Upload coverage to codeclimate
working_directory: src/api
environment:
CC_TEST_REPORTER_ID: 4969e47d48f3745fa39d4d9d717e5da88bc3e42376d665c54ba313ae3ce3189c
command: |
curl -LOs https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
chmod +x test-reporter-latest-linux-amd64
./test-reporter-latest-linux-amd64 format-coverage coverage/coverage.xml -t cobertura
./test-reporter-latest-linux-amd64 upload-coverage
- run:
name: Compress coverage results
working_directory: src/api
command: |
tar cvJf coverage_results.tar.xz coverage/codecov-result.json coverage_results/*
tar cvJf coverage_results.tar.xz coverage_results/*
- store_artifacts:
path: src/api/coverage_results.tar.xz

Expand Down
15 changes: 15 additions & 0 deletions src/api/.simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SimpleCov.start 'rails' do
add_filter '/app/indices/'
add_filter '/lib/templates/'
add_filter '/lib/memory_debugger.rb'
add_filter '/lib/memory_dumper.rb'
merge_timeout 3600
add_group 'Components', 'app/components'
add_group 'Datatables', 'app/datatables'
add_group 'Instrumentations', 'app/instrumentations'
add_group 'Mixins', 'app/mixins'
add_group 'Policies', 'app/policies'
add_group 'Queries', 'app/queries'
add_group 'Services', 'app/services'
add_group 'Validators', 'app/validators'
end
3 changes: 1 addition & 2 deletions src/api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ group :test do
# to ensure a clean state for testing
gem 'database_cleaner-active_record'
# for test coverage reports
gem 'codecov', require: false
gem 'simplecov', require: false
gem 'simplecov-cobertura', require: false
# for failing fast
gem 'minitest-fail-fast'
# for spec like reporting
Expand All @@ -164,7 +164,6 @@ group :test do
# To generate random data
gem 'rantly'
# for test analysis in CircleCI
gem 'coveralls'
gem 'minitest-ci'
gem 'rspec_junit_formatter'
# to test rabbitmq support
Expand Down
28 changes: 9 additions & 19 deletions src/api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,9 @@ GEM
activesupport
tzinfo
cocoon (1.2.15)
codecov (0.6.0)
simplecov (>= 0.15, < 0.22)
coderay (1.1.3)
colorize (0.8.1)
concurrent-ruby (1.2.2)
coveralls (0.8.23)
json (>= 1.8, < 3)
simplecov (~> 0.16.1)
term-ansicolor (~> 1.3)
thor (>= 0.19.4, < 2.0)
tins (~> 1.6)
crack (0.4.5)
rexml
crass (1.0.6)
Expand Down Expand Up @@ -436,11 +428,15 @@ GEM
set (1.0.3)
shoulda-matchers (5.1.0)
activesupport (>= 5.2.0)
simplecov (0.16.1)
simplecov (0.22.0)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-cobertura (2.1.0)
rexml
simplecov (~> 0.19)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
single_test (0.6.0)
rake
sorted_set (1.0.3)
Expand All @@ -456,11 +452,8 @@ GEM
strong_migrations (1.4.4)
activerecord (>= 5.2)
strscan (3.0.1)
sync (0.5.0)
sysexits (1.2.0)
temple (0.10.0)
term-ansicolor (1.7.1)
tins (~> 1.0)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
terser (1.1.14)
Expand All @@ -477,8 +470,6 @@ GEM
thor (1.2.1)
tilt (2.1.0)
timeout (0.3.2)
tins (1.32.1)
sync
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)
Expand Down Expand Up @@ -532,9 +523,7 @@ DEPENDENCIES
capybara_minitest_spec
clockwork
cocoon
codecov
coderay
coveralls
daemons
dalli
data_migrate
Expand Down Expand Up @@ -599,6 +588,7 @@ DEPENDENCIES
selenium-webdriver
shoulda-matchers
simplecov
simplecov-cobertura
single_test
sprockets-rails
strong_migrations
Expand Down
52 changes: 4 additions & 48 deletions src/api/lib/tasks/coverage.rake
Original file line number Diff line number Diff line change
@@ -1,56 +1,12 @@
namespace :ci do
def merged_results(glob)
coverage_results = []
base_dir = Rails.root.join('coverage_results')
Dir["#{base_dir}/" + glob].each do |file|
# load json results from coverage folder
file_results = JSON.parse(File.read(file))

# parse results from coverage file to array
file_results.each do |command, data|
result = SimpleCov::Result.from_hash(command => data)
coverage_results << result
end
end

# merge results from array to results object
SimpleCov::ResultMerger.merge_results(*coverage_results)
end

desc 'Generate merged coverage report'
task :simplecov_ci_merge do
require 'simplecov'
require 'codecov'
require 'coveralls'
require 'simplecov-cobertura'

# initialize data members
# and configure simplecov
SimpleCov.filters.clear
SimpleCov.merge_timeout 100_000

SimpleCov.configure do
add_group('WebUI') { |file| file.filename =~ /webui/ }
add_group('Jobs') { |file| file.filename =~ %r{jobs/} }
add_group('Models') { |file| file.filename =~ %r{models/} }
add_group('Helpers') { |file| file.filename =~ %r{helpers/} && file.filename !~ /webui/ }
add_group('API Controllers') { |file| file.filename =~ %r{controllers/} && file.filename !~ /webui/ }
SimpleCov.collate(Dir['coverage_results/*.json'], 'rails') do
formatter SimpleCov::Formatter::MultiFormatter.new([SimpleCov::Formatter::CoberturaFormatter,
SimpleCov::Formatter::HTMLFormatter])
end

# upload the result for all
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
Coveralls::SimpleCov::Formatter,
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Codecov
])
merged_results('resultset*.json').format!

# render subsets
SimpleCov.coverage_dir('coverage/rspec')
SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
merged_results('resultset-rspec*.json').format!

SimpleCov.coverage_dir('coverage/minitest')
SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
merged_results('resultset-minitest*.json').format!
end
end
5 changes: 0 additions & 5 deletions src/api/spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# for generating test coverage
require 'simplecov'
# Avoid codecov failures outside of CI
if ENV['CIRCLECI']
# support test coverage
require 'support/coverage'
end
# to clean old unused cassettes
require 'cassette_rewinder' if ENV['CLEAN_UNUSED_CASSETTES']

Expand Down
15 changes: 0 additions & 15 deletions src/api/spec/support/coverage.rb

This file was deleted.

17 changes: 0 additions & 17 deletions src/api/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,6 @@

Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)

if ENV['DO_COVERAGE']
ENV['CODECOV_FLAG'] = ENV.fetch('CIRCLE_STAGE', nil)
SimpleCov.start 'rails' do
# NOTE: Keep filters in sync with spec/support/coverage.rb
add_filter '/app/indices/'
add_filter '/lib/templates/'
add_filter '/lib/memory_debugger.rb'
add_filter '/lib/memory_dumper.rb'
merge_timeout 3600
end

SimpleCov.at_exit do
puts 'Coverage done'
SimpleCov.result.format!
end
end

require File.expand_path('../config/environment', __dir__)
require_relative 'test_consistency_helper'

Expand Down
2 changes: 1 addition & 1 deletion src/api/test/unit/package_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/..') + '/test_helper'

SimpleCov.command_name('test:api')
SimpleCov.command_name('minitest')

class PackageTest < ActiveSupport::TestCase
fixtures :all
Expand Down
Binary file removed src/api/vendor/cache/codecov-0.6.0.gem
Binary file not shown.
Binary file removed src/api/vendor/cache/coveralls-0.8.23.gem
Binary file not shown.
Binary file removed src/api/vendor/cache/simplecov-0.16.1.gem
Binary file not shown.
Binary file added src/api/vendor/cache/simplecov-0.22.0.gem
Binary file not shown.
Binary file not shown.
Binary file removed src/api/vendor/cache/simplecov-html-0.10.2.gem
Binary file not shown.
Binary file added src/api/vendor/cache/simplecov-html-0.12.3.gem
Binary file not shown.
Binary file not shown.
Binary file removed src/api/vendor/cache/sync-0.5.0.gem
Binary file not shown.
Binary file removed src/api/vendor/cache/term-ansicolor-1.7.1.gem
Binary file not shown.
Binary file removed src/api/vendor/cache/tins-1.32.1.gem
Binary file not shown.

0 comments on commit 5e85efa

Please sign in to comment.