Skip to content

Commit

Permalink
backport: refactoring of Rakefile now split in different task files; …
Browse files Browse the repository at this point in the history
…addition of manifest:chec to default task
  • Loading branch information
ddnexus committed Apr 20, 2021
1 parent a49ae2a commit 16f5560
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 77 deletions.
1 change: 1 addition & 0 deletions .github/ci-gemfiles/ruby-2.6+
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ gem 'rubocop-rake'

gem 'simplecov', :require => false
gem 'codecov', :require => false
gem 'rake-manifest', :require => false
6 changes: 5 additions & 1 deletion .github/workflows/pagy3-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
BUNDLE_GEMFILE: .github/ci-gemfiles/ruby-2.6+
RUBOCOP: true
CODECOV: true
RAKE_MANIFEST: true
fail-fast: false
env: ${{ matrix.env }}

Expand All @@ -56,9 +57,12 @@ jobs:
if: ${{ env.RUBOCOP == 'true' }}
run: bundle exec rubocop


- name: Codecov
if: ${{ env.CODECOV == 'true' }}
uses: codecov/codecov-action@v1.3.2
with:
fail_ci_if_error: true

- name: Check whether pagy.manifest is up-to-date in pagy3|dev3
if: ${{ env.RAKE_MANIFEST == 'true' && (endsWith(github.ref, '/pagy3') || endsWith(github.ref, '/dev3')) }}
run: bundle exec rake manifest:check
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ end
# gem 'memory_profiler'
# end

group :ide_development do
gem 'debase'
gem 'ruby-debug-ide'
end
# group :ide_development do
# gem 'debase'
# gem 'ruby-debug-ide'
# end
74 changes: 2 additions & 72 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,76 +1,6 @@
# encoding: utf-8
# frozen_string_literal: true

require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'json'
Rake.add_rakelib 'tasks'

if ENV['RUBOCOP'] == 'true' || !ENV['CI']
require "rubocop/rake_task"
RuboCop::RakeTask.new(:rubocop)
end

unless ENV['CI']
require 'rake/manifest'
Rake::Manifest::Task.new do |t|
t.patterns = %w[lib/**/* LICENSE.txt]
t.patterns = FileList.new.include('lib/**/*', 'LICENSE.txt').exclude('**/*.md')
t.manifest_file = 'pagy.manifest'
end

desc 'Build the gem, checking the manifest first'
task build: 'manifest:check'
end

# Separate tasks for each test that must run a process
# in isolation in order to avoid affecting also other tests.
test_tasks = {}

%w[ headers
i18n
i18n_old
overflow
support
shared
trim
items_trim
items_countless
items_elasticsearch
elasticsearch_rails
searchkick
].each do |name|
task_name = :"test_#{name}"
file_path = "test/**/#{name}_test.rb"
test_tasks[task_name] = file_path
Rake::TestTask.new(task_name) do |t|
test_files = FileList.new file_path
t.test_files = test_files
t.description = "Run tests in #{test_files.join(', ')}"
end
end

# Collect the other tests
Rake::TestTask.new(:test_others) do |t|
test_files = FileList.new.include('test/**/*_test.rb').exclude(*test_tasks.values)
t.test_files = test_files
t.description = "Run tests in #{test_files.join(', ')}"
end

desc 'Display SimpleCov coverage summary'
task :coverage_summary do
last_run = JSON.parse(File.read('coverage/.last_run.json'))
result = last_run['result']['line']
puts "\n>>> SimpleCov Coverage: #{result}% <<<"
if result < 100.0
Warning.warn "!!!!! Missing #{(100.0 - result).round(2)}% coverage !!!!!"
puts "\n(run it again with COVERAGE_REPORT=true for a line-by-line HTML report @ coverage/index.html)" unless ENV['COVERAGE_REPORT']
end
end

# get the full list of of all the test tasks (and test files that each task run) with:
# rake -D test_*
desc "Run all the test tasks: #{test_tasks.keys.join(', ')}"
task test: [*test_tasks.keys, :test_others]

task default: [:test, :rubocop, :coverage_summary]
task default: [:test, :rubocop, :coverage_summary, :'manifest:check']
15 changes: 15 additions & 0 deletions tasks/coverage_summary.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# encoding: utf-8
# frozen_string_literal: true

require 'json'

desc 'Display SimpleCov coverage summary'
task :coverage_summary do
last_run = JSON.parse(File.read('coverage/.last_run.json'))
result = last_run['result']['line']
puts "\n>>> SimpleCov Coverage: #{result}% <<<"
if result < 100.0
Warning.warn "!!!!! Missing #{(100.0 - result).round(2)}% coverage !!!!!"
puts "\n(run it again with COVERAGE_REPORT=true for a line-by-line HTML report @ coverage/index.html)" unless ENV['COVERAGE_REPORT']
end
end
29 changes: 29 additions & 0 deletions tasks/gem_management.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# encoding: utf-8
# frozen_string_literal: true

# gem build and release tasks, with added checks and patches
if ENV['RAKE_MANIFEST'] == 'true' || !ENV['CI']

require 'bundler/gem_tasks'
require 'rake/manifest'

Rake::Manifest::Task.new do |t|
t.patterns = FileList.new.include('lib/**/*', 'LICENSE.txt').exclude('**/*.md')
t.manifest_file = 'pagy.manifest'
end

desc 'Build the gem, checking the manifest first'
task build: 'manifest:check'

module Bundler
class GemHelper
def version_tag
"#{@tag_prefix}#{version}" # remove that stupid 'v' prepended to the version number
end
end
end

desc 'Release the gem, checking the manifest first'
task release: 'manifest:check'

end
7 changes: 7 additions & 0 deletions tasks/rubocop.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# encoding: utf-8
# frozen_string_literal: true

if ENV['RUBOCOP'] == 'true' || !ENV['CI']
require "rubocop/rake_task"
RuboCop::RakeTask.new(:rubocop)
end
44 changes: 44 additions & 0 deletions tasks/test.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# encoding: utf-8
# frozen_string_literal: true

require 'rake/testtask'

# Separate tasks for each test that must run a process
# in isolation in order to avoid affecting also other tests.
test_tasks = {}

%w[ headers
i18n
i18n_old
overflow
support
shared
trim
items_trim
items_countless
items_elasticsearch
elasticsearch_rails
searchkick
].each do |name|
task_name = :"test_#{name}"
file_path = "test/**/#{name}_test.rb"
test_tasks[task_name] = file_path
Rake::TestTask.new(task_name) do |t|
test_files = FileList.new file_path
t.test_files = test_files
t.description = "Run tests in #{test_files.join(', ')}"
end
end

# Collect the other tests
Rake::TestTask.new(:test_others) do |t|
test_files = FileList.new.include('test/**/*_test.rb').exclude(*test_tasks.values)
t.test_files = test_files
t.description = "Run tests in #{test_files.join(', ')}"
end

desc "Run all the test tasks: #{test_tasks.keys.join(', ')}"
task test: [*test_tasks.keys, :test_others]

# get the full list of of all the test tasks (and test files that each task run) with:
# rake -D test_*

0 comments on commit 16f5560

Please sign in to comment.