-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
281 lines (246 loc) · 9.24 KB
/
Rakefile
File metadata and controls
281 lines (246 loc) · 9.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# frozen_string_literal: true
# Galtzo FLOSS Rakefile v1.0.4 (rails edition) - 2025-08-14
#
# CHANGELOG
# v1.0.0 - initial release w/ support for rspec, minitest, rubocop, reek, yard, and stone_checksums
# v1.0.1 - fix test / spec tasks running 2x
# v1.0.2 - fix duplicate task warning from RuboCop
# v1.0.3 - add bench tasks to run mini benchmarks (add scripts to /benchmarks)
# v1.0.4 - add support for floss_funding:install
#
# MIT License (see License.txt)
#
# Copyright (c) 2025 Peter H. Boling (galtzo.com)
#
# Expected to work in any project that uses Bundler.
#
# Sets up tasks for floss_funding, rspec, minitest, rubocop, reek, yard, and stone_checksums.
#
# rake bench # Run all benchmarks (alias for bench:run)
# rake bench:list # List available benchmark scripts
# rake bench:run # Run all benchmark scripts (skips on CI)
# rake build # Build my_gem-1.0.0.gem into the pkg directory
# rake build:checksum # Generate SHA512 checksum of my_gem-1.0.0.gem into the checksums directory
# rake build:generate_checksums # Generate both SHA256 & SHA512 checksums into the checksums directory, and git commit them
# rake bundle:audit:check # Checks the Gemfile.lock for insecure dependencies
# rake bundle:audit:update # Updates the bundler-audit vulnerability database
# rake clean # Remove any temporary products
# rake clobber # Remove any generated files
# rake coverage # Run specs w/ coverage and open results in browser
# rake install # Build and install my_gem-1.0.0.gem into system gems
# rake install:local # Build and install my_gem-1.0.0.gem into system gems without network access
# rake reek # Check for code smells
# rake reek:update # Run reek and store the output into the REEK file
# rake release[remote] # Create tag v1.0.0 and build and push my_gem-1.0.0.gem to rubygems.org
# rake rubocop # alias rubocop task to rubocop_gradual
# rake rubocop_gradual # Run RuboCop Gradual
# rake rubocop_gradual:autocorrect # Run RuboCop Gradual with autocorrect (only when it's safe)
# rake rubocop_gradual:autocorrect_all # Run RuboCop Gradual with autocorrect (safe and unsafe)
# rake rubocop_gradual:check # Run RuboCop Gradual to check the lock file
# rake rubocop_gradual:force_update # Run RuboCop Gradual to force update the lock file
# rake spec # Run RSpec code examples
# rake test # Run tests
# rake yard # Generate YARD Documentation
require_relative "config/application"
Rails.application.load_tasks
require "rbconfig"
defaults = []
is_ci = ENV.fetch("CI", "false").casecmp("true") == 0
### DEVELOPMENT TASKS
# Setup Floss Funding
begin
require "floss_funding"
FlossFunding.install_tasks
rescue LoadError
desc("(stub) floss_funding is unavailable")
namespace(:floss_funding) do
task("install") do
warn("NOTE: floss_funding isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
end
end
end
# Setup Kettle Soup Cover
begin
require "kettle-soup-cover"
Kettle::Soup::Cover.install_tasks
# NOTE: Coverage on CI is configured independent of this task.
# This task is for local development, as it opens results in browser
defaults << "coverage" unless Kettle::Soup::Cover::IS_CI
rescue LoadError
desc("(stub) coverage is unavailable")
task("coverage") do
warn("NOTE: kettle-soup-cover isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
end
end
# Setup Bundle Audit
begin
require "bundler/audit/task"
Bundler::Audit::Task.new
defaults.push("bundle:audit:update", "bundle:audit")
rescue LoadError
desc("(stub) bundle:audit is unavailable")
task("bundle:audit") do
warn("NOTE: bundler-audit isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
end
desc("(stub) bundle:audit:update is unavailable")
task("bundle:audit:update") do
warn("NOTE: bundler-audit isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
end
end
# Setup RSpec
begin
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
# This takes the place of `coverage` task when running as CI=true
defaults << "spec" if !defined?(Kettle::Soup::Cover) || Kettle::Soup::Cover::IS_CI
rescue LoadError
desc("spec task stub")
task(:spec) do
warn("NOTE: rspec isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
end
end
# Setup MiniTest
begin
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.test_files = FileList["tests/**/test_*.rb"]
end
rescue LoadError
desc("test task stub")
task(:test) do
warn("NOTE: minitest isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
end
end
# rubocop:disable Rake/DuplicateTask
if Rake::Task.task_defined?("spec") && !Rake::Task.task_defined?("test")
desc "run spec task with test task"
task test: :spec
elsif !Rake::Task.task_defined?("spec") && Rake::Task.task_defined?("test")
desc "run test task with spec task"
task spec: :test
else
# Add spec as pre-requisite to 'test'
Rake::Task[:test].enhance(["spec"])
end
# rubocop:enable Rake/DuplicateTask
# Setup RuboCop-LTS
begin
require "rubocop/lts"
Rubocop::Lts.install_tasks
# Make autocorrect the default rubocop task
defaults << "rubocop_gradual:autocorrect"
rescue LoadError
desc("(stub) rubocop_gradual is unavailable")
task(:rubocop_gradual) do
warn("NOTE: rubocop-lts isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
end
end
# Setup Reek
begin
require "reek/rake/task"
Reek::Rake::Task.new do |t|
t.fail_on_error = true
t.verbose = false
t.source_files = "{lib,spec,tests}/**/*.rb"
end
# Store current Reek output into REEK file
require "open3"
desc("Run reek and store the output into the REEK file")
task("reek:update") do
# Run via Bundler if available to ensure the right gem version is used
cmd = [Gem.bindir ? File.join(Gem.bindir, "bundle") : "bundle", "exec", "reek"]
output, status = Open3.capture2e(*cmd)
File.write("REEK", output)
# Mirror the failure semantics of the standard reek task
unless status.success?
abort("reek:update failed (reek reported smells). Output written to REEK")
end
end
defaults << "reek:update" unless is_ci
rescue LoadError
desc("(stub) reek is unavailable")
task(:reek) do
warn("NOTE: reek isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
end
end
# Setup Yard
begin
require "yard"
YARD::Rake::YardocTask.new(:yard) do |t|
t.files = [
# Source Splats (alphabetical)
"lib/**/*.rb",
"-", # source and extra docs are separated by "-"
# Extra Files (alphabetical)
"*.cff",
"*.md",
"*.txt",
"REEK",
]
end
defaults << "yard"
rescue LoadError
desc("(stub) yard is unavailable")
task(:yard) do
warn("NOTE: yard isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
end
end
### RELEASE TASKS
# Setup stone_checksums
begin
require "stone_checksums"
GemChecksums.install_tasks
rescue LoadError
desc("(stub) build:generate_checksums is unavailable")
task("build:generate_checksums") do
warn("NOTE: stone_checksums isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
end
end
# --- Benchmarks (dev-only) ---
namespace :bench do
desc "List available benchmark scripts"
task :list do
bench_files = Dir[File.join(__dir__, "benchmarks", "*.rb")].sort
if bench_files.empty?
puts "No benchmark scripts found under benchmarks/."
else
bench_files.each { |f| puts File.basename(f) }
end
end
desc "Run all benchmark scripts (skips on CI)"
task :run do
if ENV.fetch("CI", "false").casecmp("true").zero?
puts "Benchmarks are disabled on CI. Skipping."
next
end
ruby = RbConfig.ruby
bundle = Gem.bindir ? File.join(Gem.bindir, "bundle") : "bundle"
bench_files = Dir[File.join(__dir__, "benchmarks", "*.rb")].sort
if bench_files.empty?
puts "No benchmark scripts found under benchmarks/."
next
end
use_bundler = ENV.fetch("BENCH_BUNDLER", "0") == "1"
bench_files.each do |script|
puts "\n=== Running: #{File.basename(script)} ==="
if use_bundler
cmd = [bundle, "exec", ruby, "-Ilib", script]
system(*cmd) || abort("Benchmark failed: #{script}")
else
# Run benchmarks without Bundler to reduce overhead and better reflect plain ruby -Ilib
begin
require "bundler"
Bundler.with_unbundled_env do
system(ruby, "-Ilib", script) || abort("Benchmark failed: #{script}")
end
rescue LoadError
# If Bundler isn't available, just run directly
system(ruby, "-Ilib", script) || abort("Benchmark failed: #{script}")
end
end
end
end
end
desc "Run all benchmarks (alias for bench:run)"
task bench: "bench:run"
task default: defaults