forked from thoughtworks/pacto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
121 lines (104 loc) · 3.18 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
require 'rspec/core/rake_task'
require 'cucumber'
require 'cucumber/rake/task'
require 'coveralls/rake/task'
require 'rubocop/rake_task'
require 'rake/notes/rake_task'
require 'rake/packagetask'
Dir.glob('tasks/*.rake').each { |r| import r }
Coveralls::RakeTask.new
require 'pacto/rake_task' # FIXME: This require turns on WebMock
WebMock.allow_net_connect!
Rubocop::RakeTask.new(:rubocop) do |task|
# abort rake on failure
task.fail_on_error = true
end
Cucumber::Rake::Task.new(:journeys) do |t|
t.cucumber_opts = 'features --format progress'
end
RSpec::Core::RakeTask.new(:unit) do |t|
t.pattern = 'spec/unit/**/*_spec.rb'
end
RSpec::Core::RakeTask.new(:integration) do |t|
t.pattern = 'spec/integration/**/*_spec.rb'
end
task :default => [:unit, :integration, :journeys, :samples, :rubocop, 'coveralls:push']
%w(unit integration journeys samples).each do |taskname|
task taskname => 'smoke_test_services'
end
desc 'Run the samples'
task :samples do
Dir.chdir('samples') do
Bundler.with_clean_env do
system 'bundle install'
Dir['**/*.rb'].each do | sample_code_file |
next if sample_code_file =~ /sample_api/
sh "bundle exec ruby -rbundler/setup -rrspec/autorun #{sample_code_file}"
end
Dir['**/*.sh'].each do | sample_script |
sh "./#{sample_script}"
end
end
end
end
desc 'Build the documentation from the samples'
task :documentation do
sh "docco -t #{Dir.pwd}/docco_embeddable_layout/docco.jst samples/*"
end
desc 'Build gems into the pkg directory'
task :build do
FileUtils.rm_rf('pkg')
Dir['*.gemspec'].each do |gemspec|
system "gem build #{gemspec}"
end
FileUtils.mkdir_p('pkg')
FileUtils.mv(Dir['*.gem'], 'pkg')
end
Rake::PackageTask.new('pacto_docs', Pacto::VERSION) do |p|
p.need_zip = true
p.need_tar = true
p.package_files.include('docs/**/*')
end
def changelog
changelog = File.read('CHANGELOG').split("\n\n\n", 2).first
confirm 'Does the CHANGELOG look correct? ', changelog
end
def confirm(question, data)
puts 'Please confirm...'
puts data
print question
abort 'Aborted' unless $stdin.gets.strip == 'y'
puts 'Confirmed'
data
end
desc 'Make sure the sample services are running'
task :smoke_test_services do
require 'faraday'
begin
retryable(:tries => 5, :sleep => 1) do
Faraday.get('http://localhost:5000/api/ping')
end
rescue
abort 'Could not connect to the demo services, please start them with `foreman start`'
end
end
# Retries a given block a specified number of times in the
# event the specified exception is raised. If the retries
# run out, the final exception is raised.
#
# This code is slightly adapted from https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/util/retryable.rb,
# which is in turn adapted slightly from the following blog post:
# http://blog.codefront.net/2008/01/14/retrying-code-blocks-in-ruby-on-exceptions-whatever/
def retryable(opts = nil)
opts = { :tries => 1, :on => Exception }.merge(opts || {})
begin
return yield
rescue *opts[:on] => e
if (opts[:tries] -= 1) > 0
$stderr.puts("Retryable exception raised: #{e.inspect}")
sleep opts[:sleep].to_f if opts[:sleep]
retry
end
raise
end
end