Skip to content

Commit

Permalink
Coverage refactoring:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ddnexus committed Feb 11, 2024
1 parent 3ef2141 commit 4dfe21d
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 84 deletions.
1 change: 0 additions & 1 deletion .github/gemfiles/default
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
17 changes: 5 additions & 12 deletions .github/workflows/pagy-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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/[email protected]
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


Expand Down
2 changes: 1 addition & 1 deletion .idea/runConfigurations/Test.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 4 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -153,7 +154,6 @@ PLATFORMS
DEPENDENCIES
activesupport
benchmark-ips
codecov
http
i18n
kalibera
Expand All @@ -175,6 +175,7 @@ DEPENDENCIES
rubocop-performance
rubocop-rake
simplecov
simplecov-json
sinatra
sinatra-contrib

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<span>[![Gem Version](https://img.shields.io/gem/v/pagy.svg?label=pagy&colorA=99004d&colorB=cc0066)](https://rubygems.org/gems/pagy)</span> <span>
[![ruby](https://img.shields.io/badge/ruby-EOL-ruby.svg?colorA=99004d&colorB=cc0066)](https://endoflife.date/ruby)</span> <span>
[![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)</span> <span>
[![codecov](https://codecov.io/gh/ddnexus/pagy/graph/badge.svg?token=S7wBqMwPlQ)](https://codecov.io/gh/ddnexus/pagy)</span> <span>
![Coverage](https://img.shields.io/badge/coverage-100%25-coverage.svg?colorA=1f7a1f&colorB=2aa22a)</span> <span>
![Rubocop Status](https://img.shields.io/badge/rubocop-passing-rubocop.svg?colorA=1f7a1f&colorB=2aa22a)</span> <span>
[![MIT license](https://img.shields.io/badge/license-MIT-mit.svg?colorA=1f7a1f&colorB=2aa22a)](http://opensource.org/licenses/MIT)</span> <span>
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/4329/badge)](https://bestpractices.coreinfrastructure.org/projects/4329)</span> <span>
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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]
25 changes: 25 additions & 0 deletions tasks/check_coverage.rake
Original file line number Diff line number Diff line change
@@ -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
20 changes: 0 additions & 20 deletions tasks/coverage_summary.rake

This file was deleted.

34 changes: 0 additions & 34 deletions test/coverage_setup.rb

This file was deleted.

8 changes: 2 additions & 6 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 4dfe21d

Please sign in to comment.