-
Notifications
You must be signed in to change notification settings - Fork 24
/
Rakefile
88 lines (76 loc) · 2.51 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
require 'bundler/gem_tasks'
require 'rake/clean'
require 'rake/testtask'
require 'cucumber/rake/task'
require 'yard'
require 'rubygems/comparator'
require 'launchy'
require 'mechanize'
require 'fileutils'
CLOBBER.include('pkg')
CLEAN.include('build')
# Documentation
YARD::Rake::YardocTask.new do |t|
t.files = ['lib/**/*.rb', 'plugins/**/*.rb']
t.options = []
t.stats_options = ['--list-undoc']
end
task :init do
FileUtils.mkdir_p 'build'
end
# Default test task
desc 'Run all unit tests'
Rake::TestTask.new do |t|
t.pattern = 'test/**/*_test.rb'
t.libs << 'test'
end
# Cucumber acceptance test tasks
Cucumber::Rake::Task.new(:features)
task :features => :init
namespace :features do
desc 'Opens the HTML Cucumber test report'
task :open_report do
Launchy.open('./build/features_report.html')
end
end
# Compare latest release with current git head
task compare: [:clean, :build] do
git_version = VagrantPlugins::Registration::VERSION
options = {}
options[:output] = 'pkg'
options[:keep_all] = true
comparator = Gem::Comparator.new(options)
comparator.compare_versions('vagrant-registration', ['_', git_version])
comparator.print_results
end
desc 'Download CDK Vagrant box using the specified provider (default \'virtualbox\')'
task :get_cdk, [:provider] do |t, args|
provider = args[:provider].nil? ? 'virtualbox' : args[:provider]
agent = Mechanize.new
agent.follow_meta_refresh = true
agent.get(CDK_DOWNLOAD_URL) do |page|
# Submit first form which is the redirect to login page form
login_page = page.forms.first.submit
# Submit the login form
after_login = login_page.form_with(:name => 'login_form') do |f|
username_field = f.field_with(:id => 'username')
username_field.value = '[email protected]'
password_field = f.field_with(:id => 'password')
password_field.value = 'service-manager'
end.click_button
# There is one more redirect after successful login
download_page = after_login.forms.first.submit
download_page.links.each do |link|
if link.href =~ /#{Regexp.quote(CDK_BOX_BASE_NAME)}-#{Regexp.quote(provider)}.box/
download_dir = File.join(File.dirname(__FILE__), 'build', 'boxes')
unless File.directory?(download_dir)
FileUtils.mkdir_p(download_dir)
end
agent.pluggable_parser.default = Mechanize::Download
puts "Downloading #{link.href}"
agent.get(link.href).save(File.join(download_dir, "cdk-#{provider}.box"))
end
end
end
end
task :get_cdk => :init