-
-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathRakefile
More file actions
206 lines (178 loc) · 6.76 KB
/
Copy pathRakefile
File metadata and controls
206 lines (178 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
204
205
206
#!/usr/bin/env rake
# =========================================================================
# Ceedling - Test-Centered Build System for C
# ThrowTheSwitch.org
# Copyright (c) 2010-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
# SPDX-License-Identifier: MIT
# =========================================================================
require 'bundler'
require 'rspec/core/rake_task'
require 'fileutils'
require 'open3'
##
## Testing tasks
##
# Local developer gets hierarchical documentation output; CI gets compact progress output.
# Most CI systems (GitHub Actions, GitLab CI, CircleCI, etc.) set CI=true automatically.
RSPEC_FORMAT = ENV['CI_RSPEC_PROGRESS_FORMAT'] ? '--format progress' : '--format documentation'
desc "Run unit specs only"
RSpec::Core::RakeTask.new('specs:units') do |t|
t.pattern = 'spec/units/**/*_spec.rb'
t.rspec_opts = RSPEC_FORMAT
end
desc "Run system specs only"
RSpec::Core::RakeTask.new('specs:system') do |t|
t.pattern = 'spec/system/**/*_spec.rb'
t.rspec_opts = RSPEC_FORMAT
end
# Run unit tests first to fail on fast before running slower system tests
desc "Run all specs: units first then system (non-debug)"
task 'specs:all' => ['specs:units', 'specs:system']
# CI batch debug mode: run all system specs, keeping only failure artifacts.
# Passing project directories are deleted immediately; passing logs are never written.
desc "Run all system specs with artifact retention for failures only"
task 'specs:system:debug' do
ENV['CEEDLING_SYSTEM_TEST_KEEP'] = 'failures'
Rake::Task['specs:system'].invoke
end
# Individual unit specs
Dir['spec/units/**/*_spec.rb'].each do |p|
base = File.basename(p,'.*').gsub('_spec','')
desc "Run unit spec: #{base}"
RSpec::Core::RakeTask.new("spec:unit:#{base}") do |t|
t.pattern = p
t.rspec_opts = '--format documentation'
end
end
# Individual system specs
Dir['spec/system/**/*_spec.rb'].each do |p|
base = File.basename(p,'.*').gsub('_spec','')
desc "Run system spec: #{base}"
RSpec::Core::RakeTask.new("spec:system:#{base}") do |t|
t.pattern = p
t.rspec_opts = '--format documentation'
end
end
# Individual system specs with full artifact retention (unadvertised).
# Developer debug mode: preserve all artifacts — both pass and fail project directories and logs
Dir['spec/system/**/*_spec.rb'].each do |p|
base = File.basename(p,'.*').gsub('_spec','')
task "spec:system:debug:#{base}" do
ENV['CEEDLING_SYSTEM_TEST_KEEP'] = 'all'
Rake::Task["spec:system:#{base}"].invoke
end
end
desc "Run specs by filename matching a substring (e.g., rake \"spec:filter:filename[<substring>]\")"
RSpec::Core::RakeTask.new('spec:filter:filename', [:pattern]) do |t, args|
pattern = args[:pattern] || '*'
t.pattern = "spec/{units,system}/**/*#{pattern}*_spec.rb"
t.rspec_opts = '--format documentation'
end
desc "Run specs matching an example's description (e.g., rake \"spec:filter:example[Version reporting]\")"
RSpec::Core::RakeTask.new('spec:filter:example', [:description]) do |t, args|
description = args[:description] || ''
t.pattern = 'spec/{units,system}/**/*_spec.rb'
t.rspec_opts = "--format documentation --example '#{description}'"
end
desc "Run specs whose example's description matches a regex pattern (e.g., rake \"spec:filter:match[version|help]\")"
RSpec::Core::RakeTask.new('spec:filter:match', [:regex]) do |t, args|
regex = args[:regex] || ''
t.pattern = 'spec/{units,system}/**/*_spec.rb'
t.rspec_opts = "--format documentation --pattern '#{regex}'"
end
##
## Default & CI tasks
##
task :default => ['specs:all']
task :ci => [:no_color, :default]
##
## Documentation tasks
##
task :no_color do
#doesn't do anything at the moment. will remove color from output for CI
end
# Docs tasks Python virtual environment activate / deactivate wrapper
# This wrapper skips venv actions if no venv is in use (such as in CI)
def venv_sh(cmd)
puts "Running: #{cmd}"
script = <<~SHELL
_activated=0
if [ -z "$VIRTUAL_ENV" ] && [ -f ".docsenv/bin/activate" ]; then
source .docsenv/bin/activate
_activated=1
fi
#{cmd}
if [ "$_activated" = "1" ]; then deactivate; fi
SHELL
sh('bash', '-c', script, verbose: false) do |ok, res|
raise "ERROR: '#{cmd}' failed (exit #{res.exitstatus})" unless ok
end
end
namespace :docs do
desc "Install documentation tooling (mkdocs-material, mike) in a Python virtual environment"
task :install do
venv_dir = '.docsenv'
if File.directory?(venv_dir)
puts "Python virtual environment '#{venv_dir}/' already exists — skipping creation."
else
puts "Creating Python virtual environment '#{venv_dir}/'..."
output, status = Open3.capture2e("python3 -m venv #{venv_dir}")
unless status.success?
$stderr.puts output
raise "Failed to create Python virtual environment '#{venv_dir}/'"
end
puts "Python virtual environment '#{venv_dir}/' created."
end
puts "Installing documentation packages (mkdocs, mkdocs-material, mike)..."
output, status = Open3.capture2e('bash', '-c', <<~SHELL)
_activated=0
if [ -z "$VIRTUAL_ENV" ]; then
source #{venv_dir}/bin/activate
_activated=1
fi
pip install 'mkdocs>=1.6' 'mkdocs-material>=9.5' 'mike>=2.0'
if [ "$_activated" = "1" ]; then deactivate; fi
SHELL
unless status.success?
$stderr.puts output
raise "Failed to install documentation packages"
end
puts "Documentation packages installed."
end
desc "Snapshot versioned project files into docs/snapshot/ for documentation"
task :snapshot do
snapshot_dir = 'docs/mkdocs/snapshot/'
# Ensure the snapshot directory is empty before writing new files (to clear out anything stale)
FileUtils.rm_rf(snapshot_dir)
ruby "lib/snapshot.rb", "docs/mkdocs/snapshot.yml", snapshot_dir
end
namespace :build do
desc "Build documentation site for web deployment"
task :web => [:snapshot] do
venv_sh "mkdocs build --strict"
end
desc "Build documentation site as local HTML files bundle"
task :local => [:snapshot] do
venv_sh "mkdocs build -f mkdocs.local.yml --strict"
end
end
desc "Serve web deploy docs site locally on port 8000"
task :serve do
venv_sh "mkdocs serve"
end
desc "Browse versioned docs site locally on port 8000"
task :preview do
venv_sh "mike serve"
end
namespace :deploy do
desc "Deploy 'dev' version to Github Pages"
task :dev => [:snapshot] do
venv_sh "mike deploy --push dev"
end
desc "Deploy a release version to Github Pages (usage: rake docs:deploy:release[1.1.0])"
task :release, [:version] => [:snapshot] do |t, args|
version = args[:version] || raise("Version required: rake docs:deploy:release[#.#.#]")
venv_sh "mike deploy --push #{version} latest"
end
end
end