-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRakefile
More file actions
126 lines (107 loc) · 3.54 KB
/
Rakefile
File metadata and controls
126 lines (107 loc) · 3.54 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
# frozen_string_literal: true
require 'rake'
require 'minitest/test_task'
require 'bundler/gem_tasks'
require 'rubocop/rake_task'
require 'net/http'
require 'open3'
require 'shellwords'
require 'timeout'
require 'yard'
require 'yard/rake/yardoc_task'
RuboCop::RakeTask.new
YARD::Rake::YardocTask.new(:yard)
Minitest::TestTask.create(:test) do |task|
task.libs << 'lib'
task.libs << 'test'
task.test_globs = ['test/*/**/*.rb']
task.warning = true
end
QUICK_TEST_FILES = Dir['test/*/**/*.rb'].reject { |file| file.start_with?('test/integration/') }.sort.freeze
# Returns the local NATS JetStream health endpoint used by the CI helpers.
#
# @return [URI::HTTP] The health endpoint URI.
def nats_health_uri = URI('http://127.0.0.1:8222/healthz')
# Reports whether the local NATS JetStream health endpoint is currently reachable.
#
# @return [Boolean] `true` when the broker responds successfully, otherwise `false`.
def nats_ready?
Net::HTTP.get_response(nats_health_uri).is_a?(Net::HTTPSuccess)
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET
false
end
# Waits for the local NATS JetStream broker to report healthy.
#
# @return [void]
# @raise [RuntimeError] If the broker does not become healthy within 30 seconds.
def wait_for_nats!
Timeout.timeout(30) do
sleep 1 until nats_ready?
end
rescue Timeout::Error
raise 'Timed out waiting for NATS JetStream health endpoint on http://127.0.0.1:8222/healthz'
end
# Detects the container runtime used to manage the local NATS broker.
#
# @return [String] `podman` when available, otherwise `docker`.
def container_runtime
File.executable?('/usr/bin/podman') || system('command -v podman > /dev/null 2>&1', exception: false) ? 'podman' : 'docker'
end
# Runs the non-integration test files directly for a fast local feedback loop.
#
# @return [void]
def run_quick_tests!
sh "ruby -w -Ilib -Itest #{QUICK_TEST_FILES.shelljoin}"
end
# Verifies that the current YARD coverage is complete.
#
# @return [void]
# @raise [RuntimeError] If YARD reports anything less than 100% documentation coverage.
def verify_yard_coverage!
output, status = Open3.capture2e('bundle', 'exec', 'yard', 'stats', '--list-undoc')
puts output
raise 'yard stats failed' unless status.success?
return if output.include?('100.00% documented')
raise 'YARD documentation coverage is incomplete'
end
namespace :nats do
desc 'Start the local NATS JetStream broker via ./ci/nats/start.sh'
task :start do
sh({ 'NATS_DETACH' => '1' }, './ci/nats/start.sh')
end
desc 'Wait for the local NATS JetStream broker health endpoint'
task :wait do
wait_for_nats!
end
desc 'Stop the local NATS JetStream broker container'
task :stop do
name = ENV.fetch('NATS_NAME', 'leopard-nats')
sh(container_runtime, 'rm', '-f', name, verbose: false)
rescue RuntimeError
nil
end
end
namespace :ci do
desc 'Run RuboCop, YARD verification, and the non-integration test suite without managing NATS'
task quick: %i[rubocop yard:verify] do
run_quick_tests!
end
desc 'Run the full test suite against a managed local NATS JetStream broker'
task :test do
Rake::Task['nats:start'].invoke
Rake::Task['nats:wait'].invoke
Rake::Task['test'].invoke
ensure
Rake::Task['nats:stop'].reenable
Rake::Task['nats:stop'].invoke
end
end
desc 'Run RuboCop and the full test suite against a managed local NATS JetStream broker'
task ci: %w[rubocop yard:verify ci:test]
namespace :yard do
desc 'Fail if YARD reports incomplete documentation coverage'
task :verify do
verify_yard_coverage!
end
end
task default: :ci