Rakefile in pacto-0.3.1 vs Rakefile in pacto-0.4.0.rc1
- old
+ new
@@ -1,17 +1,19 @@
require 'rspec/core/rake_task'
-require 'pacto/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
-Rubocop::RakeTask.new(:rubocop) do |task|
- # abort rake on failure
+require 'pacto/rake_task' # FIXME: This require turns on WebMock
+WebMock.allow_net_connect!
+
+RuboCop::RakeTask.new(:rubocop) do |task|
task.fail_on_error = true
end
Cucumber::Rake::Task.new(:journeys) do |t|
t.cucumber_opts = 'features --format progress'
@@ -23,42 +25,87 @@
RSpec::Core::RakeTask.new(:integration) do |t|
t.pattern = 'spec/integration/**/*_spec.rb'
end
-task :default => [:unit, :integration, :journeys, :rubocop, 'coveralls:push']
+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
+ FileUtils.rm_rf('samples/tmp')
+ sh 'bundle exec polytrix exec --solo=samples --solo-glob="*.{rb,sh}"'
+ sh 'bundle exec polytrix generate code2doc --solo=samples --solo-glob="*.{rb,sh}"'
+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
-desc 'Tags version, pushes to remote, and pushes gems'
-task :release => :build do
- sh 'git', 'tag', '-m', changelog, "v#{Pacto::VERSION}"
- sh 'git push origin master'
- sh "git push origin v#{Pacto::VERSION}"
- sh 'ls pkg/*.gem | xargs -n 1 gem push'
+Rake::PackageTask.new('pacto_docs', Pacto::VERSION) do |p|
+ p.need_zip = true
+ p.need_tar = true
+ p.package_files.include('docs/**/*')
end
-task :changelog do
- changelog
-end
-
def changelog
changelog = File.read('CHANGELOG').split("\n\n\n", 2).first
- confirm "Does the CHANGELOG look correct? ", changelog
+ confirm 'Does the CHANGELOG look correct? ', changelog
end
def confirm(question, data)
- puts "Please confirm..."
+ puts 'Please confirm...'
puts data
print question
- abort "Aborted" unless $stdin.gets.strip == 'y'
- puts "Confirmed"
+ 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