Skip to content

Commit bd69f9b

Browse files
committed
build: refactor Rakefile by splitting tasks into separate files
The monolithic 79-line Rakefile has been refactored into a clean 15-line loader that dynamically imports task definitions from the tasks/ directory. Changes: - Created tasks/ directory with 5 focused rake files: - tasks/test.rake - test execution tasks - tasks/rubocop.rake - RuboCop linting tasks - tasks/yard.rake - YARD documentation tasks - tasks/gem_tasks.rake - gem building and release tasks - tasks/test_gem.rake - gem sanity check task - Main Rakefile now: - Loads all .rake files from tasks/ directory - Dynamically builds default task list based on available tasks - Simplified from 79 lines to 15 lines - Moved platform-specific logic (JRuby/TruffleRuby check) into yard.rake where it belongs - Maintained all original functionality and default task behavior: - Default tasks: test, rubocop, yard, yardstick:coverage, build - yardstick remains commented out of defaults (too many warnings) This refactoring improves maintainability and separation of concerns while preserving all existing rake task functionality.
1 parent 4a7700d commit bd69f9b

File tree

6 files changed

+74
-72
lines changed

6 files changed

+74
-72
lines changed

Rakefile

Lines changed: 11 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,18 @@
11
# frozen_string_literal: true
22

3-
require 'bundler/gem_tasks'
4-
require 'English'
3+
require 'rake/clean'
54

6-
require 'git/version'
5+
# Load all .rake files from tasks and its subdirectories.
6+
Dir.glob('tasks/**/*.rake').each { |r| load r }
77

88
default_tasks = []
9-
10-
desc 'Run Unit Tests'
11-
task :test do
12-
sh 'ruby bin/test'
13-
14-
# You can run individual test files (or multiple files) from the command
15-
# line with:
16-
#
17-
# $ bin/test test_archive.rb
18-
#
19-
# $ bin/test test_archive.rb test_object.rb
20-
end
21-
default_tasks << :test
22-
23-
# Rubocop
24-
25-
require 'rubocop/rake_task'
26-
27-
RuboCop::RakeTask.new
28-
29-
default_tasks << :rubocop
30-
31-
# YARD
32-
33-
unless RUBY_PLATFORM == 'java' || RUBY_ENGINE == 'truffleruby'
34-
#
35-
# YARD documentation for this project can NOT be built with JRuby.
36-
# This project uses the redcarpet gem which can not be installed on JRuby.
37-
#
38-
require 'yard'
39-
YARD::Rake::YardocTask.new
40-
CLEAN << '.yardoc'
41-
CLEAN << 'doc'
42-
default_tasks << :yard
43-
44-
require 'yardstick/rake/verify'
45-
Yardstick::Rake::Verify.new(:'yardstick:coverage') do |t|
46-
t.threshold = 50
47-
t.require_exact_threshold = false
48-
end
49-
default_tasks << :'yardstick:coverage'
50-
51-
desc 'Run yardstick to check yard docs'
52-
task :yardstick do
53-
sh "yardstick 'lib/**/*.rb'"
54-
end
55-
# Do not include yardstick as a default task for now since there are too many
56-
# warnings. Will work to get the warnings down before re-enabling it.
57-
#
58-
# default_tasks << :yardstick
59-
end
60-
61-
default_tasks << :build
9+
default_tasks << :test if Rake::Task.task_defined?(:test)
10+
default_tasks << :rubocop if Rake::Task.task_defined?(:rubocop)
11+
default_tasks << :yard if Rake::Task.task_defined?(:yard)
12+
default_tasks << :'yardstick:coverage' if Rake::Task.task_defined?(:'yardstick:coverage')
13+
# Do not include yardstick as a default task for now since there are too many
14+
# warnings. Will work to get the warnings down before re-enabling it.
15+
# default_tasks << :yardstick if Rake::Task.task_defined?(:yardstick)
16+
default_tasks << :build if Rake::Task.task_defined?(:build)
6217

6318
task default: default_tasks
64-
65-
desc 'Build and install the git gem and run a sanity check'
66-
task 'test:gem': :install do
67-
output = `ruby -e "require 'git'; g = Git.open('.'); puts g.log.size"`.chomp
68-
raise 'Gem test failed' unless $CHILD_STATUS.success?
69-
raise 'Expected gem test to return an integer' unless output =~ /^\d+$/
70-
71-
puts 'Gem Test Succeeded'
72-
end
73-
74-
# Make it so that calling `rake release` just calls `rake release:rubygem_push` to
75-
# avoid creating and pushing a new tag.
76-
77-
Rake::Task['release'].clear
78-
desc 'Customized release task to avoid creating a new tag'
79-
task release: 'release:rubygem_push'

tasks/gem_tasks.rake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
require 'bundler/gem_tasks'
4+
5+
# Make it so that calling `rake release` just calls `rake release:rubygem_push` to
6+
# avoid creating and pushing a new tag.
7+
8+
Rake::Task['release'].clear
9+
desc 'Customized release task to avoid creating a new tag'
10+
task release: 'release:rubygem_push'

tasks/rubocop.rake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
require 'rubocop/rake_task'
4+
5+
RuboCop::RakeTask.new

tasks/test.rake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
desc 'Run Unit Tests'
4+
task :test do
5+
sh 'ruby bin/test'
6+
7+
# You can run individual test files (or multiple files) from the command
8+
# line with:
9+
#
10+
# $ bin/test test_archive.rb
11+
#
12+
# $ bin/test test_archive.rb test_object.rb
13+
end

tasks/test_gem.rake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require 'English'
4+
5+
desc 'Build and install the git gem and run a sanity check'
6+
task 'test:gem': :install do
7+
output = `ruby -e "require 'git'; g = Git.open('.'); puts g.log.size"`.chomp
8+
raise 'Gem test failed' unless $CHILD_STATUS.success?
9+
raise 'Expected gem test to return an integer' unless output =~ /^\d+$/
10+
11+
puts 'Gem Test Succeeded'
12+
end

tasks/yard.rake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
# YARD documentation for this project can NOT be built with JRuby or TruffleRuby.
4+
# This project uses the redcarpet gem which can not be installed on JRuby.
5+
#
6+
unless RUBY_PLATFORM == 'java' || RUBY_ENGINE == 'truffleruby'
7+
require 'yard'
8+
9+
YARD::Rake::YardocTask.new
10+
CLEAN << '.yardoc'
11+
CLEAN << 'doc'
12+
13+
require 'yardstick/rake/verify'
14+
Yardstick::Rake::Verify.new(:'yardstick:coverage') do |t|
15+
t.threshold = 50
16+
t.require_exact_threshold = false
17+
end
18+
19+
desc 'Run yardstick to check yard docs'
20+
task :yardstick do
21+
sh "yardstick 'lib/**/*.rb'"
22+
end
23+
end

0 commit comments

Comments
 (0)