From 4dfe21dbeae2060dda12550c25fc6da0fb2f9cc8 Mon Sep 17 00:00:00 2001
From: Domizio Demichelis
Date: Sun, 11 Feb 2024 08:41:19 +0700
Subject: [PATCH] Coverage refactoring:
- Removed codecov (too buggy and useless for pagy)
- Simplified and normalized the SimpleCov setup
- Replaced coverage_summary task by check_coverage
- Replaced the codecov CI step to check_coverage
- Added coverage static badge
---
.github/gemfiles/default | 1 -
.github/workflows/pagy-ci.yml | 17 +++-------
.idea/runConfigurations/Test.xml | 2 +-
.../{Test___Cov.xml => Test___CovReport.xml} | 4 +--
...Cov.xml => Test___Rubocop___CovReport.xml} | 2 +-
.simplecov | 29 ++++++++++++++++
Gemfile | 1 -
Gemfile.lock | 7 ++--
README.md | 2 +-
Rakefile | 4 +--
tasks/check_coverage.rake | 25 ++++++++++++++
tasks/coverage_summary.rake | 20 -----------
test/coverage_setup.rb | 34 -------------------
test/test_helper.rb | 8 ++---
14 files changed, 72 insertions(+), 84 deletions(-)
rename .idea/runConfigurations/{Test___Cov.xml => Test___CovReport.xml} (94%)
rename .idea/runConfigurations/{Test___Rubocop___Cov.xml => Test___Rubocop___CovReport.xml} (94%)
create mode 100644 .simplecov
create mode 100644 tasks/check_coverage.rake
delete mode 100644 tasks/coverage_summary.rake
delete mode 100644 test/coverage_setup.rb
diff --git a/.github/gemfiles/default b/.github/gemfiles/default
index 35aa88260..736c649e8 100644
--- a/.github/gemfiles/default
+++ b/.github/gemfiles/default
@@ -14,7 +14,6 @@ gem 'rake-manifest'
group :test do
gem 'activesupport'
- gem 'codecov', '>= 0.6', require: false # for some reason only ruby 3.2 install v 0.2 if not explicitly declared
gem 'minitest'
gem 'minitest-reporters'
gem 'rematch'
diff --git a/.github/workflows/pagy-ci.yml b/.github/workflows/pagy-ci.yml
index 8e3054380..5d7b5feb3 100644
--- a/.github/workflows/pagy-ci.yml
+++ b/.github/workflows/pagy-ci.yml
@@ -45,8 +45,6 @@ jobs:
- ruby-version: '3.3'
env:
BUNDLE_GEMFILE: .github/gemfiles/default
- CODECOV: true
- CHECK_MANIFEST: true
# RUBYOPT: '--disable-error_highlight'
fail-fast: false
env: ${{ matrix.env }}
@@ -60,21 +58,16 @@ jobs:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- - name: Run Ruby Tests
+ - name: Check Tests
run: bundle exec rake test
- - name: Run Rubocop
- run: bundle exec rubocop --format github
+ - name: Check Coverage
+ run: bundle exec rake check_coverage
- - name: Run Codecov
- if: ${{ env.CODECOV == 'true' }}
- uses: codecov/codecov-action@v3.1.4
- with:
- fail_ci_if_error: true
- token: ${{ secrets.CODECOV_TOKEN }}
+ - name: Check Rubocop compliance
+ run: bundle exec rubocop --format github
- name: Check gem manifest
- if: ${{ env.CHECK_MANIFEST == 'true' }}
run: bundle exec rake manifest:check
diff --git a/.idea/runConfigurations/Test.xml b/.idea/runConfigurations/Test.xml
index c8ddbe905..21e83a00c 100644
--- a/.idea/runConfigurations/Test.xml
+++ b/.idea/runConfigurations/Test.xml
@@ -34,7 +34,7 @@
-
+
diff --git a/.idea/runConfigurations/Test___Cov.xml b/.idea/runConfigurations/Test___CovReport.xml
similarity index 94%
rename from .idea/runConfigurations/Test___Cov.xml
rename to .idea/runConfigurations/Test___CovReport.xml
index 972f1b8c2..8bf5e7304 100644
--- a/.idea/runConfigurations/Test___Cov.xml
+++ b/.idea/runConfigurations/Test___CovReport.xml
@@ -1,5 +1,5 @@
-
+
@@ -28,7 +28,7 @@
-
+
diff --git a/.idea/runConfigurations/Test___Rubocop___Cov.xml b/.idea/runConfigurations/Test___Rubocop___CovReport.xml
similarity index 94%
rename from .idea/runConfigurations/Test___Rubocop___Cov.xml
rename to .idea/runConfigurations/Test___Rubocop___CovReport.xml
index 20d62adca..72db4753e 100644
--- a/.idea/runConfigurations/Test___Rubocop___Cov.xml
+++ b/.idea/runConfigurations/Test___Rubocop___CovReport.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/.simplecov b/.simplecov
new file mode 100644
index 000000000..5d2c14609
--- /dev/null
+++ b/.simplecov
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+SimpleCov.formatter = if ENV['HTML_REPORTS'] == 'true'
+ SimpleCov::Formatter::HTMLFormatter
+ else
+ SimpleCov::Formatter::SimpleFormatter
+ end
+
+SimpleCov.start do
+ command_name "Task##{$PROCESS_ID}" # best way to get a different id for the specific task
+ merge_timeout 60
+ enable_coverage :branch
+
+ add_group 'All Extras', %w[lib/pagy/extras]
+ add_group 'Core', %w[lib/pagy.rb
+ lib/pagy/backend.rb
+ lib/pagy/console.rb
+ lib/pagy/countless.rb
+ lib/pagy/exceptions.rb
+ lib/pagy/frontend.rb
+ lib/pagy/i18n.rb
+ lib/pagy/url_helpers.rb]
+ add_group 'Countless', %w[lib/pagy/countless.rb
+ lib/pagy/extras/countless.rb]
+ add_group 'Calendar', %w[lib/pagy/extras/calendar.rb
+ lib/pagy/calendar]
+ # add_filter "/test/"
+ add_group 'Tests', %w[test]
+end
diff --git a/Gemfile b/Gemfile
index da2a123c0..f0ad4ad80 100644
--- a/Gemfile
+++ b/Gemfile
@@ -11,7 +11,6 @@ gem 'readline-ext' # temporary fix for RM 3.3.2 console with ruby >= 3.3.0
group :test do
gem 'activesupport'
- gem 'codecov', require: false
gem 'i18n'
gem 'minitest'
gem 'minitest-reporters'
diff --git a/Gemfile.lock b/Gemfile.lock
index c7bc37966..f2acb01f4 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -19,8 +19,6 @@ GEM
benchmark-ips (2.13.0)
bigdecimal (3.1.6)
builder (3.2.4)
- codecov (0.6.0)
- simplecov (>= 0.15, < 0.22)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
docile (1.4.0)
@@ -128,6 +126,9 @@ GEM
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
+ simplecov-json (0.2.3)
+ json
+ simplecov
simplecov_json_formatter (0.1.4)
sinatra (4.0.0)
mustermann (~> 3.0)
@@ -153,7 +154,6 @@ PLATFORMS
DEPENDENCIES
activesupport
benchmark-ips
- codecov
http
i18n
kalibera
@@ -175,6 +175,7 @@ DEPENDENCIES
rubocop-performance
rubocop-rake
simplecov
+ simplecov-json
sinatra
sinatra-contrib
diff --git a/README.md b/README.md
index ef3eee88c..726cc893a 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
[![Gem Version](https://img.shields.io/gem/v/pagy.svg?label=pagy&colorA=99004d&colorB=cc0066)](https://rubygems.org/gems/pagy)
[![ruby](https://img.shields.io/badge/ruby-EOL-ruby.svg?colorA=99004d&colorB=cc0066)](https://endoflife.date/ruby)
[![Build Status](https://img.shields.io/github/actions/workflow/status/ddnexus/pagy/pagy-ci.yml?branch=master)](https://github.com/ddnexus/pagy/actions/workflows/pagy-ci.yml?query=branch%3Amaster)
-[![codecov](https://codecov.io/gh/ddnexus/pagy/graph/badge.svg?token=S7wBqMwPlQ)](https://codecov.io/gh/ddnexus/pagy)
+![Coverage](https://img.shields.io/badge/coverage-100%25-coverage.svg?colorA=1f7a1f&colorB=2aa22a)
![Rubocop Status](https://img.shields.io/badge/rubocop-passing-rubocop.svg?colorA=1f7a1f&colorB=2aa22a)
[![MIT license](https://img.shields.io/badge/license-MIT-mit.svg?colorA=1f7a1f&colorB=2aa22a)](http://opensource.org/licenses/MIT)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/4329/badge)](https://bestpractices.coreinfrastructure.org/projects/4329)
diff --git a/Rakefile b/Rakefile
index 65b5605c4..e31d448fd 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,5 +2,5 @@
Rake.add_rakelib 'tasks'
-task default: %i[test rubocop coverage_summary manifest:check]
-task testsum: %i[test coverage_summary]
+task default: %i[test rubocop check_coverage manifest:check]
+task test_cov: %i[test check_coverage]
diff --git a/tasks/check_coverage.rake b/tasks/check_coverage.rake
new file mode 100644
index 000000000..221dabf9a
--- /dev/null
+++ b/tasks/check_coverage.rake
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+require 'json'
+
+# If you use the RubyMine coverage command to run the rake default (test),
+# RubyMine will run the coverage with its tools thus this task will be skipped.
+desc 'Display coverage summary. Fail if not 100%'
+task :check_coverage do
+ return if ENV['RUBYMINE_SIMPLECOV_COVERAGE_PATH']
+
+ last_run = JSON.parse(File.read(File.expand_path('../coverage/.last_run.json', __dir__)))
+ line = last_run['result']['line']
+ branch = last_run['result']['branch']
+ message = "\n>>> Coverage -> line: #{line}% -> branch: #{branch}%\n"
+ message << ">>> Missing #{(100.0 - line).round(2)}% of line coverage!\n" if line < 100
+ message << ">>> Missing #{(100.0 - branch).round(2)}% of branch coverage!\n" if branch < 100
+ if line < 100 || branch < 100
+ message << ">>> Run the task again with HTML_REPORTS=true for a line-by-line HTML report @ coverage/index.html\n" \
+ unless ENV['HTML_REPORTS']
+ warn message
+ exit 1
+ else
+ puts message
+ end
+end
diff --git a/tasks/coverage_summary.rake b/tasks/coverage_summary.rake
deleted file mode 100644
index d2c97c875..000000000
--- a/tasks/coverage_summary.rake
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-require 'json'
-
-# If you use the RubyMine coverage command to run the rake default (test),
-# RubyMine will run the coverage with its tools thus this task will be skipped.
-desc 'Display SimpleCov coverage summary'
-task :coverage_summary do
- unless ENV['RUBYMINE_SIMPLECOV_COVERAGE_PATH']
- last_run = JSON.parse(File.read('coverage/.last_run.json'))
- line = last_run['result']['line']
- branch = last_run['result']['branch']
- message = "\n>>> Coverage -> line: #{line}% -> branch: #{branch}%\n"
- message << ">>> Missing #{(100.0 - line).round(2)}% of line coverage!\n" if line < 100.0
- message << ">>> Missing #{(100.0 - branch).round(2)}% of branch coverage!\n" if branch < 100.0
- message << ">>> Run the task again with HTML_REPORTS=true for a line-by-line HTML report @ coverage/index.html\n" \
- if (line < 100 || branch < 100) && !ENV['HTML_REPORTS']
- puts "#{message}\n"
- end
-end
diff --git a/test/coverage_setup.rb b/test/coverage_setup.rb
deleted file mode 100644
index 4162428d8..000000000
--- a/test/coverage_setup.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: true
-
-require 'simplecov'
-
-# Coverage by SimpleCov/CodeCov
-if ENV['CODECOV']
- require 'codecov' # require also simplecov
- # if you want the formatter to upload the results use SimpleCov::Formatter::Codecov instead
- SimpleCov.formatter = Codecov::SimpleCov::Formatter # upload with step in github actions
-elsif !ENV['CI'] # exclude in CI
- SimpleCov.configure do
- command_name "Task##{$PROCESS_ID}"
- merge_timeout 60
- enable_coverage :branch
- add_group 'All Extras', 'lib/pagy/extras'
- add_group 'Core', %w[ lib/pagy.rb
- lib/pagy/backend.rb
- lib/pagy/console.rb
- lib/pagy/countless.rb
- lib/pagy/exceptions.rb
- lib/pagy/frontend.rb
- lib/pagy/i18n.rb
- lib/pagy/url_helpers.rb ]
- add_group 'Countless', %w[ lib/pagy/countless.rb
- lib/pagy/extras/countless.rb ]
- add_group 'Calendar', %w[ lib/pagy/extras/calendar.rb
- lib/pagy/calendar ]
- # add_filter "/test/"
- add_group 'Tests', 'test'
- end
-
- SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter unless ENV.fetch('HTML_REPORTS', nil) == 'true'
- SimpleCov.start
-end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index b41e22382..92f0be438 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,17 +1,13 @@
# frozen_string_literal: true
-# rubocop:disable Lint/RedundantCopDisableDirective, Style/FetchEnvVar
-$VERBOSE = { 'false' => false, 'true' => true }[ENV['VERBOSE']] if ENV['VERBOSE']
-# rubocop:enable Lint/RedundantCopDisableDirective, Style/FetchEnvVar
-
-require_relative 'coverage_setup' unless ENV['RUBYMINE_SIMPLECOV_COVERAGE_PATH'] # skipped if RubyMine run with coverage
+require 'simplecov' unless ENV['RUBYMINE_SIMPLECOV_COVERAGE_PATH'] # skipped if RubyMine run with coverage
unless ENV['RM_INFO'] # RubyMine safe
require "minitest/reporters"
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
end
-# we cannot use gemspec in the gemfile which would load pagy before simplecov so missing files from coverage
+# We cannot use gemspec in the gemfile which would load pagy before simplecov so missing the coverage
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'pagy'
require 'minitest/autorun'