From 01f8f1ce286e9ec846ae9d7b02aec24fc511a169 Mon Sep 17 00:00:00 2001
From: Domizio Demichelis
Date: Tue, 20 Apr 2021 08:51:27 +0700
Subject: [PATCH] refactoring of Rakefile now split in different task files
---
Rakefile | 69 +------------------------------------
tasks/coverage_summary.rake | 14 ++++++++
tasks/gem_management.rake | 27 +++++++++++++++
tasks/rubocop.rake | 5 +++
tasks/test.rake | 43 +++++++++++++++++++++++
5 files changed, 90 insertions(+), 68 deletions(-)
create mode 100644 tasks/coverage_summary.rake
create mode 100644 tasks/gem_management.rake
create mode 100644 tasks/rubocop.rake
create mode 100644 tasks/test.rake
diff --git a/Rakefile b/Rakefile
index 227b4f416..539bbba20 100644
--- a/Rakefile
+++ b/Rakefile
@@ -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]
diff --git a/tasks/coverage_summary.rake b/tasks/coverage_summary.rake
new file mode 100644
index 000000000..20fcc4758
--- /dev/null
+++ b/tasks/coverage_summary.rake
@@ -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
diff --git a/tasks/gem_management.rake b/tasks/gem_management.rake
new file mode 100644
index 000000000..ad6ca507e
--- /dev/null
+++ b/tasks/gem_management.rake
@@ -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'
diff --git a/tasks/rubocop.rake b/tasks/rubocop.rake
new file mode 100644
index 000000000..73e00e5fa
--- /dev/null
+++ b/tasks/rubocop.rake
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+require 'rubocop/rake_task'
+
+RuboCop::RakeTask.new(:rubocop)
\ No newline at end of file
diff --git a/tasks/test.rake b/tasks/test.rake
new file mode 100644
index 000000000..22dca9f5d
--- /dev/null
+++ b/tasks/test.rake
@@ -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_*