forked from puppetlabs/bolt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
268 lines (226 loc) · 8.93 KB
/
Rakefile
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
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "rubocop/rake_task"
require "bolt/cli"
require "puppet-strings"
require "fileutils"
require "json"
require "erb"
# Needed for Vanagon component ship job
require 'packaging'
Pkg::Util::RakeUtils.load_packaging_tasks
desc "Run all RSpec tests"
RSpec::Core::RakeTask.new(:spec)
desc "Run RSpec tests that don't require VM fixtures or a particular shell"
RSpec::Core::RakeTask.new(:unit) do |t|
t.rspec_opts = '--tag ~ssh --tag ~docker --tag ~bash --tag ~winrm ' \
'--tag ~appveyor_agents --tag ~puppetserver --tag ~puppetdb ' \
'--tag ~omi --tag ~kerberos'
end
desc "Run RSpec tests for AppVeyor that don't require SSH, Bash, Appveyor Puppet Agents, or orchestrator"
RSpec::Core::RakeTask.new(:appveyor) do |t|
t.rspec_opts = '--tag ~ssh --tag ~docker --tag ~bash --tag ~appveyor_agents ' \
'--tag ~orchestrator --tag ~puppetserver --tag ~puppetdb --tag ~omi ' \
'--tag ~kerberos'
end
desc "Run RSpec tests for TravisCI that don't require WinRM"
RSpec::Core::RakeTask.new(:travisci) do |t|
t.rspec_opts = '--tag ~winrm --tag ~appveyor_agents --tag ~puppetserver --tag ~puppetdb ' \
'--tag ~omi --tag ~windows --tag ~kerberos --tag ~expensive'
end
desc "Run RSpec tests that are slow or require slow to start containers for setup"
RSpec::Core::RakeTask.new(:puppetserver) do |t|
t.rspec_opts = '--tag puppetserver --tag puppetdb --tag expensive'
end
RuboCop::RakeTask.new(:rubocop) do |t|
t.options = ['--display-cop-names', '--display-style-guide', '--parallel']
end
desc "Run tests and style checker"
task test: %w[spec rubocop]
task :default do
system "rake --tasks"
end
def format_links(text)
text.gsub(/{([^}]+)}/, '[`\1`](#\1)')
end
namespace :travis do
task rubocop: :rubocop
task :unit do
sh "docker-compose -f spec/docker-compose.yml build --parallel ubuntu_node puppet_5_node puppet_6_node"
sh "docker-compose -f spec/docker-compose.yml up -d ubuntu_node puppet_5_node puppet_6_node"
sh "r10k puppetfile install"
Rake::Task['travisci'].invoke
end
task :modules do
success = true
%w[boltlib ctrl file out system].each do |mod|
Dir.chdir("#{__dir__}/bolt-modules/#{mod}") do
sh 'rake spec' do |ok, _|
success = false unless ok
end
end
end
raise "Module tests failed" unless success
end
task docs: :generate_docs
task :integration do
sh "docker-compose -f spec/docker-compose.yml build --parallel"
sh "docker-compose -f spec/docker-compose.yml up -d"
sh "r10k puppetfile install"
# Wait for containers to be started
result = 15.times do
ready = sh('[ -z "$(docker ps -q --filter=health=starting)" ]') { |ok, _| ok }
break :ready if ready
sleep(5)
end
if result == :ready
Rake::Task['puppetserver'].invoke
else
raise "Containers did not properly start"
end
end
end
namespace :docs do
desc "Generate markdown docs for Bolt's transport configuration options"
task :config_reference do
@transports = { options: {}, defaults: {} }
@global = { options: Bolt::Config::OPTIONS, defaults: Bolt::Config::DEFAULT_OPTIONS }
@log = { options: Bolt::Config::LOG_OPTIONS, defaults: Bolt::Config::DEFAULT_LOG_OPTIONS }
@puppetfile = { options: Bolt::Config::PUPPETFILE_OPTIONS }
Bolt::TRANSPORTS.each do |name, transport|
@transports[:options][name.to_s] = transport::OPTIONS
@transports[:defaults][name.to_s] = transport&.default_options
end
renderer = ERB.new(File.read('documentation/bolt_configuration_reference.md.erb'), nil, '-')
File.write('documentation/bolt_configuration_reference.md', renderer.result)
end
desc "Generate markdown docs for Bolt's command line options"
task :cli_reference do
parser = Bolt::BoltOptionParser.new({})
@commands = {}
Bolt::CLI::COMMANDS.each do |subcommand, actions|
actions << nil if actions.empty?
actions.each do |action|
command = [subcommand, action].compact.join(' ')
help_text = parser.get_help_text(subcommand, action)
options = help_text[:flags].map do |option|
switch = parser.top.long[option]
{
short: switch.short.first,
long: switch.long.first,
arg: switch.arg,
desc: switch.desc.map { |d| d.gsub("<", "<") }.join("<br>")
}
end
@commands[command] = {
banner: help_text[:banner],
options: options
}
end
end
# It's nice to have the subcommands/actions sorted alphabetically in the docs
# We could get around this by sorting the COMMANDS hash in the CLI
@commands = @commands.sort.to_h
renderer = ERB.new(File.read('documentation/bolt_command_reference.md.erb'), nil, '-')
File.write('documentation/bolt_command_reference.md', renderer.result)
end
desc "Generate markdown docs for Bolt's core Puppet functions"
task :function_reference do
FileUtils.mkdir_p 'tmp'
tmpfile = 'tmp/boltlib.json'
PuppetStrings.generate(['bolt-modules/*'],
markup: 'markdown', json: true, path: tmpfile,
yard_args: ['bolt-modules/boltlib',
'bolt-modules/ctrl',
'bolt-modules/file',
'bolt-modules/out',
'bolt-modules/system'])
json = JSON.parse(File.read(tmpfile))
funcs = json.delete('puppet_functions')
json.delete('data_types')
json.each { |k, v| raise "Expected #{k} to be empty, found #{v}" unless v.empty? }
# @functions will be a list of function descriptions, structured as
# name: function name
# text: function description; first line should be usable as a summary
# signatures: a list of function overloads
# text: overload description
# signature: function signature
# returns: list of return statements
# text: return description
# types: list of types (probably only one entry)
# params: list of params
# name: parameter name
# text: description
# types: list of types (probably only one entry)
# examples: list of examples
# name: description
# text: example body
@functions = funcs.map do |func|
func['text'] = func['docstring']['text']
overloads = func['docstring']['tags'].select { |tag| tag['tag_name'] == 'overload' }
sig_tags = overloads.map { |overload| overload['docstring']['tags'] }
sig_tags = [func['docstring']['tags']] if sig_tags.empty?
func['signatures'] = func['signatures'].zip(sig_tags).map do |sig, tags|
sig['text'] = sig['docstring']['text']
sects = sig['docstring']['tags'].group_by { |t| t['tag_name'] }
sig['returns'] = sects['return'].map do |ret|
ret['text'] = format_links(ret['text'])
ret
end
sig['params'] = sects['param'].map do |param|
param['text'] = format_links(param['text'])
param
end
# get examples from overload docstring; puppet-strings should probably do this.
examples = tags.select { |t| t['tag_name'] == 'example' }
sig['examples'] = examples
sig.delete('docstring')
sig
end
func
end
renderer = ERB.new(File.read('documentation/reference.md.erb'), nil, '-')
File.write('documentation/plan_functions.md', renderer.result)
end
task all: %i[cli_reference function_reference config_reference]
end
desc 'Generate all markdown docs'
task generate_docs: 'docs:all'
namespace :integration do
desc 'Run tests that require a host System Under Test configured with WinRM'
RSpec::Core::RakeTask.new(:winrm) do |t|
t.rspec_opts = '--tag winrm'
end
desc 'Run tests that require a host System Under Test configured with SSH'
RSpec::Core::RakeTask.new(:ssh) do |t|
t.rspec_opts = '--tag ssh'
end
desc 'Run tests that require a host System Under Test configured with Docker'
RSpec::Core::RakeTask.new(:docker) do |t|
t.rspec_opts = '--tag docker'
end
desc 'Run tests that require Bash on the local host'
RSpec::Core::RakeTask.new(:bash) do |t|
t.rspec_opts = '--tag bash'
end
desc 'Run tests that require windows OS on the local host'
RSpec::Core::RakeTask.new(:windows) do |t|
t.rspec_opts = '--tag windows'
end
desc 'Run tests that require Puppet Agents configured with Appveyor'
RSpec::Core::RakeTask.new(:appveyor_agents) do |t|
t.rspec_opts = '--tag appveyor_agents'
end
desc 'Run tests that require OMI docker container'
RSpec::Core::RakeTask.new(:omi) do |t|
t.rspec_opts = '--tag omi'
end
task ssh: :update_submodules
task winrm: :update_submodules
task :update_submodules do
sh 'git submodule update --init'
end
end
spec = Gem::Specification.find_by_name 'gettext-setup'
load "#{spec.gem_dir}/lib/tasks/gettext.rake"