-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRakefile
More file actions
203 lines (176 loc) · 6.76 KB
/
Rakefile
File metadata and controls
203 lines (176 loc) · 6.76 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
# frozen_string_literal: true
# Galtzo FLOSS Rakefile v1.0.2 (modified) - 2025-08-12
#
# 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 rspec, minitest, rubocop, reek, yard, and stone_checksums.
#
# 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 / run spec task with test task
# rake yard # Generate YARD Documentation
require "bundler/gem_tasks"
defaults = []
is_ci = ENV.fetch("CI", "false").casecmp("true") == 0
### DEVELOPMENT TASKS
# 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
task default: defaults
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)