Skip to content

Commit

Permalink
refactoring of Rakefile now split in different task files
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Apr 20, 2021
1 parent b3aeece commit 01f8f1c
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 68 deletions.
69 changes: 1 addition & 68 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,72 +1,5 @@
# frozen_string_literal: true

require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rubocop/rake_task'
require 'json'

RuboCop::RakeTask.new(:rubocop)

unless ENV['CI']
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'
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
overflow
support
oj_shared
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.load_file('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]
Rake.add_rakelib 'tasks'

task default: %i[test rubocop coverage_summary]
14 changes: 14 additions & 0 deletions tasks/coverage_summary.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require 'json'

desc 'Display SimpleCov coverage summary'
task :coverage_summary do
last_run = JSON.load_file('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
27 changes: 27 additions & 0 deletions tasks/gem_management.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

return if ENV['CI']

# gem build and release tasks, with added checks and patches

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'
5 changes: 5 additions & 0 deletions tasks/rubocop.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

require 'rubocop/rake_task'

RuboCop::RakeTask.new(:rubocop)
43 changes: 43 additions & 0 deletions tasks/test.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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
overflow
support
oj_shared
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 01f8f1c

Please sign in to comment.