-
Notifications
You must be signed in to change notification settings - Fork 40
/
Rakefile
57 lines (49 loc) · 1.58 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
desc "Test to ensure the site will compile from scratch"
task :test do
FileUtils.rm_r('build') if File.exist?('build')
sh "middleman", "build", "--verbose"
end
desc "Test Swagger files to ensure they pass specifications."
task :lint do
require "open3"
require "yaml"
swagger_specs = `grep -l -r -i --include '*.yml' --include '*.json' swagger ./source ./build`.split("\n")
if($?.exitstatus != 0)
puts swagger_specs
exit 1
end
errors = {}
swagger_specs.each do |file|
puts file
# Validate the YAML with Ruby's validator. Note that this helps catch YAML
# syntax errors that the swagger validator and NodeJS's YAML parser seem to
# be okay with, but that the online swagger validator (which is apparently
# Java) errors on.
begin
YAML.load_file(file)
rescue => e
output = "YAML error: #{e.message}"
puts "#{output}\n\n\n"
errors[file] = output
end
# Validate the swagger spec
unless errors[file]
output, status = Open3.capture2e("./node_modules/.bin/swagger-tools", "validate", "-v", file)
output = output.to_s.strip
puts "#{output}\n\n\n"
# swagger-tools doesn't exit with an unsuccessful code on warnings, so also
# manually check the output.
if(!status.success? || !output.include?("Swagger document is valid"))
errors[file] = output
end
end
end
if(errors.any?)
puts "===== ERROR: Swagger validation errors =====\n\n\n"
errors.each do |file, output|
puts "#{file}\n#{output}\n\n\n"
end
exit 1
end
end
task :default => [:test, :lint]