-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathRakefile
More file actions
90 lines (76 loc) · 2.21 KB
/
Rakefile
File metadata and controls
90 lines (76 loc) · 2.21 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
require 'bundler/gem_tasks'
require 'rake/testtask'
task :default => [:test]
desc 'Run all tests'
task :test => [:unit, :integration]
desc 'Run unit tests'
task :unit do
Rake::TestTask.new do |t|
t.name = 'unit'
t.libs << 'test/unit'
t.test_files = FileList['test/unit/**/*_test.rb']
t.verbose = true
end
end
desc 'Run integration tests'
task :integration do
Rake::TestTask.new do |t|
t.name = 'integration'
t.libs << "test/integration"
t.test_files = FileList['test/integration/**/*_test.rb']
t.verbose = true
end
end
desc 'Build APIs'
task :API => 'API:all'
namespace :API do
task :all => [:setup, :run]
desc 'Cleans APIs build'
task :clean do
require 'fileutils'
FileUtils.rm_r('build') if Dir.exist?('build')
end
desc 'Prepare APIs Build'
task :setup do
Dir.mkdir('build') unless Dir.exist?('build')
Dir.mkdir('build/APIs') unless Dir.exist?('build/APIs')
unless Dir.exist?('./build/openstack-APIs')
`git clone https://github.com/flystack/openstack-APIs build/openstack-APIs`
end
end
desc 'Process APIs'
task :run do
require 'pp'
require 'yaml'
Dir.glob("build/openstack-APIs/APIs/*/*.yaml") do |entry|
ext = ''
path = entry.gsub('.yaml', '').split('/')
name = path[-2]
version = path[-1].gsub(/\./, '_')
ext << '_ext' if version =~ /_ext/
payload = YAML.load_file(entry)
Dir.mkdir("build/APIs/#{name}") unless Dir.exist?("build/APIs/#{name}")
puts "Generating build/APIs/#{name}/#{name}_#{version}.rb"
File.open("build/APIs/#{name}/#{name}_#{version}.rb", 'w') do |f|
f << "module Misty::Openstack::API::#{name.capitalize}#{version.capitalize}\n"
f << " def tag\n"
f << " '#{payload[:tag]}'\n"
f << " end\n\n"
f << " def api#{ext}\n"
PP.pp(payload[:api], f)
f << " end\n"
f << "end\n"
end
end
end
desc 'Compare APIs'
task :diff do
Dir.glob("build/APIs/*/*.rb") do |entry|
path = entry.split('/')
name = path[-2]
file = path[-1]
`diff lib/misty/openstack/api/#{name}/#{file} build/APIs/#{name}/#{file}`
puts "Not the same: #{name}/#{file}" unless $? == 0
end
end
end