From 7e3825fd303f6f56929e9ca6bbfad87bec2d303a Mon Sep 17 00:00:00 2001 From: Alex Skrenchuk Date: Wed, 16 Nov 2022 23:05:22 -0800 Subject: [PATCH] Add code coverage report uploads to codecove.io --- .github/workflows/ruby-unit-test.yml | 7 +++---- Gemfile | 10 +++++++--- Gemfile.lock | 16 +++++++++++----- test/test_case.rb | 13 ++++++++++--- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ruby-unit-test.yml b/.github/workflows/ruby-unit-test.yml index 538d2570..ccb161f3 100644 --- a/.github/workflows/ruby-unit-test.yml +++ b/.github/workflows/ruby-unit-test.yml @@ -16,11 +16,9 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Install Depenencies + - name: Install Dependencies run: sudo apt-get -y install raptor2-utils - name: Set up Ruby - # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, - # change this to (see https://github.com/ruby/setup-ruby#versioning): uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} @@ -29,5 +27,6 @@ jobs: run: docker compose up -d - name: Run tests run: bundle exec rake test - + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 diff --git a/Gemfile b/Gemfile index fa8578f2..e4e50c06 100644 --- a/Gemfile +++ b/Gemfile @@ -5,12 +5,16 @@ gemspec gem "activesupport" gem "cube-ruby", require: "cube" gem "faraday", '~> 1.9' -gem "minitest", '< 5.0' -gem "pry" gem "rake" -gem "simplecov", require: false, group: :test gem "uuid" +group :test do + gem "minitest", '< 5.0' + gem "pry" + gem 'simplecov' + gem 'simplecov-cobertura' # for submitting code coverage results to codecov.io +end + group :profiling do gem "rack-accept" gem "rack-post-body-to-params" diff --git a/Gemfile.lock b/Gemfile.lock index a1dff571..99315b6e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,20 +93,21 @@ GEM rack (>= 0.4) rack-post-body-to-params (0.1.8) activesupport (>= 2.3) - rack-protection (3.0.2) + rack-protection (3.0.3) rack rake (13.0.6) rdf (1.0.8) addressable (>= 2.2) redis (5.0.5) redis-client (>= 0.9.0) - redis-client (0.11.0) + redis-client (0.11.1) connection_pool rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) + rexml (3.2.5) rsolr (2.5.0) builder (>= 2.1.2) faraday (>= 0.9, < 3, != 2.0.0) @@ -115,12 +116,15 @@ GEM docile (~> 1.1) 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) - sinatra (3.0.2) + sinatra (3.0.3) mustermann (~> 3.0) rack (~> 2.2, >= 2.2.4) - rack-protection (= 3.0.2) + rack-protection (= 3.0.3) tilt (~> 2.0) systemu (2.6.5) thin (1.8.1) @@ -139,6 +143,7 @@ GEM PLATFORMS ruby x86_64-darwin-16 + x86_64-linux DEPENDENCIES activesupport @@ -151,10 +156,11 @@ DEPENDENCIES rack-post-body-to-params rake simplecov + simplecov-cobertura sinatra sparql-client! thin uuid BUNDLED WITH - 2.3.15 + 2.3.22 diff --git a/test/test_case.rb b/test/test_case.rb index fa2b3706..82d9c50e 100644 --- a/test/test_case.rb +++ b/test/test_case.rb @@ -1,6 +1,13 @@ -# Start simplecov if this is a coverage task -if ENV["COVERAGE"].eql?("true") - require 'simplecov' +# Start simplecov if this is a coverage task or if it is run in the CI pipeline +if ENV["COVERAGE"] == "true" || ENV["CI"] == "true" + require "simplecov" + require "simplecov-cobertura" + # https://github.com/codecov/ruby-standard-2 + # Generate HTML and Cobertura reports which can be consumed by codecov uploader + SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::CoberturaFormatter + ]) SimpleCov.start do add_filter "/test/" add_filter "app.rb"