Skip to content

Commit 9bf5205

Browse files
authored
🔨 Galtzo FLOSS Rakefile v1.0.2
1 parent 5a20891 commit 9bf5205

File tree

1 file changed

+195
-9
lines changed

1 file changed

+195
-9
lines changed

‎Rakefile‎

Lines changed: 195 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,201 @@
1+
# frozen_string_literal: true
2+
3+
# Galtzo FLOSS Rakefile v1.0.2 - 2025-08-12
4+
#
5+
# MIT License (see License.txt)
6+
#
7+
# Copyright (c) 2025 Peter H. Boling (galtzo.com)
8+
#
9+
# Expected to work in any project that uses Bundler.
10+
#
11+
# Sets up tasks for rspec, minitest, rubocop, reek, yard, and stone_checksums.
12+
#
13+
# rake build # Build my_gem-1.0.0.gem into the pkg directory
14+
# rake build:checksum # Generate SHA512 checksum of my_gem-1.0.0.gem into the checksums directory
15+
# rake build:generate_checksums # Generate both SHA256 & SHA512 checksums into the checksums directory, and git commit them
16+
# rake bundle:audit:check # Checks the Gemfile.lock for insecure dependencies
17+
# rake bundle:audit:update # Updates the bundler-audit vulnerability database
18+
# rake clean # Remove any temporary products
19+
# rake clobber # Remove any generated files
20+
# rake coverage # Run specs w/ coverage and open results in browser
21+
# rake install # Build and install my_gem-1.0.0.gem into system gems
22+
# rake install:local # Build and install my_gem-1.0.0.gem into system gems without network access
23+
# rake reek # Check for code smells
24+
# rake reek:update # Run reek and store the output into the REEK file
25+
# rake release[remote] # Create tag v1.0.0 and build and push my_gem-1.0.0.gem to rubygems.org
26+
# rake rubocop # alias rubocop task to rubocop_gradual
27+
# rake rubocop_gradual # Run RuboCop Gradual
28+
# rake rubocop_gradual:autocorrect # Run RuboCop Gradual with autocorrect (only when it's safe)
29+
# rake rubocop_gradual:autocorrect_all # Run RuboCop Gradual with autocorrect (safe and unsafe)
30+
# rake rubocop_gradual:check # Run RuboCop Gradual to check the lock file
31+
# rake rubocop_gradual:force_update # Run RuboCop Gradual to force update the lock file
32+
# rake spec # Run RSpec code examples
33+
# rake test # Run tests / run spec task with test task
34+
# rake yard # Generate YARD Documentation
35+
136
require "bundler/gem_tasks"
237

3-
require "kettle-soup-cover"
4-
Kettle::Soup::Cover.install_tasks
38+
defaults = []
39+
40+
is_ci = ENV.fetch("CI", "false").casecmp("true") == 0
41+
42+
### DEVELOPMENT TASKS
43+
# Setup Kettle Soup Cover
44+
begin
45+
require "kettle-soup-cover"
46+
47+
Kettle::Soup::Cover.install_tasks
48+
# NOTE: Coverage on CI is configured independent of this task.
49+
# This task is for local development, as it opens results in browser
50+
defaults << "coverage" unless Kettle::Soup::Cover::IS_CI
51+
rescue LoadError
52+
desc("(stub) coverage is unavailable")
53+
task("coverage") do
54+
warn("NOTE: kettle-soup-cover isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
55+
end
56+
end
57+
58+
# Setup Bundle Audit
59+
begin
60+
require "bundler/audit/task"
61+
62+
Bundler::Audit::Task.new
63+
defaults.push("bundle:audit:update", "bundle:audit")
64+
rescue LoadError
65+
desc("(stub) bundle:audit is unavailable")
66+
task("bundle:audit") do
67+
warn("NOTE: bundler-audit isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
68+
end
69+
desc("(stub) bundle:audit:update is unavailable")
70+
task("bundle:audit:update") do
71+
warn("NOTE: bundler-audit isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
72+
end
73+
end
74+
75+
# Setup RSpec
76+
begin
77+
require "rspec/core/rake_task"
78+
79+
RSpec::Core::RakeTask.new(:spec)
80+
# This takes the place of `coverage` task when running as CI=true
81+
defaults << "spec" if !defined?(Kettle::Soup::Cover) || Kettle::Soup::Cover::IS_CI
82+
rescue LoadError
83+
desc("spec task stub")
84+
task(:spec) do
85+
warn("NOTE: rspec isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
86+
end
87+
end
88+
89+
# Setup MiniTest
90+
begin
91+
require "rake/testtask"
92+
93+
Rake::TestTask.new(:test) do |t|
94+
t.test_files = FileList["tests/**/test_*.rb"]
95+
end
96+
rescue LoadError
97+
desc("test task stub")
98+
task(:test) do
99+
warn("NOTE: minitest isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
100+
end
101+
end
102+
103+
# rubocop:disable Rake/DuplicateTask
104+
if Rake::Task.task_defined?("spec") && !Rake::Task.task_defined?("test")
105+
desc "run spec task with test task"
106+
task test: :spec
107+
elsif !Rake::Task.task_defined?("spec") && Rake::Task.task_defined?("test")
108+
desc "run test task with spec task"
109+
task spec: :test
110+
else
111+
# Add spec as pre-requisite to 'test'
112+
Rake::Task[:test].enhance(["spec"])
113+
end
114+
# rubocop:enable Rake/DuplicateTask
115+
116+
# Setup RuboCop-LTS
117+
begin
118+
require "rubocop/lts"
119+
120+
Rubocop::Lts.install_tasks
121+
# Make autocorrect the default rubocop task
122+
defaults << "rubocop_gradual:autocorrect"
123+
rescue LoadError
124+
desc("(stub) rubocop_gradual is unavailable")
125+
task(:rubocop_gradual) do
126+
warn("NOTE: rubocop-lts isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
127+
end
128+
end
129+
130+
# Setup Reek
131+
begin
132+
require "reek/rake/task"
133+
134+
Reek::Rake::Task.new do |t|
135+
t.fail_on_error = true
136+
t.verbose = false
137+
t.source_files = "{lib,spec,tests}/**/*.rb"
138+
end
139+
140+
# Store current Reek output into REEK file
141+
require "open3"
142+
desc("Run reek and store the output into the REEK file")
143+
task("reek:update") do
144+
# Run via Bundler if available to ensure the right gem version is used
145+
cmd = [Gem.bindir ? File.join(Gem.bindir, "bundle") : "bundle", "exec", "reek"]
146+
147+
output, status = Open3.capture2e(*cmd)
148+
149+
File.write("REEK", output)
150+
151+
# Mirror the failure semantics of the standard reek task
152+
unless status.success?
153+
abort("reek:update failed (reek reported smells). Output written to REEK")
154+
end
155+
end
156+
defaults << "reek:update" unless is_ci
157+
rescue LoadError
158+
desc("(stub) reek is unavailable")
159+
task(:reek) do
160+
warn("NOTE: reek isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
161+
end
162+
end
163+
164+
# Setup Yard
165+
begin
166+
require "yard"
5167

6-
require "rspec/core/rake_task"
7-
RSpec::Core::RakeTask.new(:spec)
168+
YARD::Rake::YardocTask.new(:yard) do |t|
169+
t.files = [
170+
# Source Splats (alphabetical)
171+
"lib/**/*.rb",
172+
"-", # source and extra docs are separated by "-"
173+
# Extra Files (alphabetical)
174+
"*.cff",
175+
"*.md",
176+
"*.txt",
177+
"REEK",
178+
]
179+
end
180+
defaults << "yard"
181+
rescue LoadError
182+
desc("(stub) yard is unavailable")
183+
task(:yard) do
184+
warn("NOTE: yard isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
185+
end
186+
end
8187

9-
desc "alias test task to spec"
10-
task test: :spec
188+
### RELEASE TASKS
189+
# Setup stone_checksums
190+
begin
191+
require "stone_checksums"
11192

12-
require "rubocop/lts"
13-
Rubocop::Lts.install_tasks
193+
GemChecksums.install_tasks
194+
rescue LoadError
195+
desc("(stub) build:generate_checksums is unavailable")
196+
task("build:generate_checksums") do
197+
warn("NOTE: stone_checksums isn't installed, or is disabled for #{RUBY_VERSION} in the current environment")
198+
end
199+
end
14200

15-
task default: %i[spec rubocop]
201+
task default: defaults

0 commit comments

Comments
 (0)