require 'rake/clean' require 'rake/packagetask' task :set_writable do Dir.glob('**/Gemfile.lock').each do |f| File.chmod(0644, f) end end Rake::PackageTask.new('helix-web-services', :noversion) do |package| package.need_tar = true package.package_files.include('doc/**/*') package.package_files.include('git_fusion_strings/**/*') package.package_files.include('helix_web_services/**/*') package.package_files.include('helix_web_services_client/**/*') package.package_files.include('packaging/**/*') package.package_files.include('Gemfile') package.package_files.include('Gemfile.lock') package.package_files.include('Rakefile') package.package_files.include('LICENSE') end CLEAN.include('pkg') task :package => [:set_writable] desc 'Rebuild the main ASCIIDoc documentation' task :asciidoc do system('bundle exec asciidoctor -o doc-output/p4ws.html doc/p4ws.asc') || fail('asciidoctor failed') end CLEAN.include('**/doc-output') namespace :all do desc 'Rebuild documentation across system' task :doc => [:asciidoc] do system('cd helix_web_services_client && bundle exec rake yard') || fail('rake yard failed for helix_web_services_client') system('cd helix_web_services && bundle exec rake yard') || fail('rake yard failed for helix_web_services') end end desc 'Run unit and integrated tests against a local development server' task :test do error = initialize_p4d error ||= initialize_development_unicorn error ||= run_server_tests error ||= run_client_tests cleanup fail('tests failed, see output for details') if error end CLEAN.include('**/spec-output') desc 'Run integrated client tests against a remote server' task :remotetest, [:host] do |task, args| error = initialize_remote_p4d(args[:host]) error ||= run_remote_client_tests(args[:host]) fail('tests failed, see output for details') if error end def initialize_p4d puts 'starting p4d' ok = system('p4util kill') return true unless ok if Dir.exist?('/tmp/p4util/p4droot') require 'fileutils' FileUtils.rmtree('/tmp/p4util/p4droot') end ok = system('p4util start') return true unless ok ok = system('p4util init data/p4init') return true unless ok end def initialize_remote_p4d(host) ok = system("p4util init -p #{host}:1666 -a data/p4init.pkg") return true unless ok end def initialize_development_unicorn puts 'starting unicorn' begin ok = system( 'cd helix_web_services && ' + 'WORKSPACE_DIR=/tmp/tokens ' + 'UNICORN_PID=/tmp/unicorn.pid ' + 'HWS_STDOUT_PATH=/tmp/unicorn.out ' + 'HWS_STDERR_PATH=/tmp/unicorn.err ' + 'bundle exec unicorn -c config/unicorn.rb -D' ) return true unless ok while connect_to_server == false sleep(0.1) end return false rescue Exception => e puts "Error: #{e.message}" return true end end def connect_to_server require 'socket' begin s = TCPSocket.new 'localhost', 9000 s.close return true rescue Exception => e return false end end def run_server_tests ok = system('cd helix_web_services && bundle exec rake spec') return true unless ok end def run_client_tests ok = system('cd helix_web_services_client && bundle exec rake spec') return true unless ok end def run_remote_client_tests(host) ok = system("cd helix_web_services_client && P4PORT=#{host}:1666 WS_URL=https://#{host}/hws rake spec") return true unless ok end def cleanup ok = system('p4util kill') return true unless ok if Dir.exist?('/tmp/p4util/p4droot') require 'fileutils' FileUtils.rmtree('/tmp/p4util/p4droot') end if File.exist?('/tmp/unicorn.pid') unicorn_pid = IO.read('/tmp/unicorn.pid').to_i puts "killing pid: #{unicorn_pid}" Process.kill('TERM', unicorn_pid) File.unlink('/tmp/unicorn.pid') end end desc 'Create primary source deliverables' task :build => [:package]