require 'rake/clean' require 'rake/packagetask' # TODO this may not be necessary, and replaced via Salt tasks namespace :db do desc 'Create local databases (p4_project_services)' task :create do sh 'PGPASSWORD=rein4ce createdb -U postgres -h 192.168.99.100 p4_project_services' or fail 'createdb failed for p4_project_services' sh 'PGPASSWORD=rein4ce createdb -U postgres -h 192.168.99.100 notification_services' or fail 'createdb failed for notification_services' sh 'PGPASSWORD=rein4ce createdb -U postgres -h 192.168.99.100 p4_phoenix_services' or fail 'createdb failed for p4_phoenix_services' end desc 'Run migrations' task :migrate do |t, args| require 'sequel' Sequel.extension :migration puts 'Migrating p4_project_services to latest' url = 'postgres://postgres:rein4ce@192.168.99.100:5432/p4_project_services' db = Sequel.connect(url) Sequel::Migrator.run(db, 'p4_project_services/p4_project_services/migrations') puts 'Migrating notification_services to latest' url = 'postgres://postgres:rein4ce@192.168.99.100:5432/notification_services' db = Sequel.connect(url) Sequel::Migrator.run(db, 'notification_services/notification_services/migrations') puts 'Migrating p4_phoenix_services to latest' url = 'postgres://postgres:rein4ce@192.168.99.100:5432/p4_phoenix_services' db = Sequel.connect(url) Sequel::Migrator.run(db, 'p4_phoenix_services/p4_phoenix_services/migrations') end end namespace :test do begin require 'rspec/core/rake_task' # # p4util, while handy, may need to be redesigned a bit with docker-compose # # in mind. We very likely need to only perform steps that do not require # # restart - so something like a "run unicode mode" will not work. # desc 'Initialize Perforce server with test data' # task :initp4 do # sh 'bundle exec p4util init -p "`docker-machine ip`:1666" p4_project_services/clients/ruby/p4_project_services_client/spec/init/' or fail 'p4util init failed' # end RSpec::Core::RakeTask.new(:p4_web_api) do |t| t.pattern = 'p4_web_api/clients/ruby/p4_web_api_client/spec/*.rb' end RSpec::Core::RakeTask.new(:p4_project_services) do |t| t.pattern = 'p4_project_services/clients/ruby/p4_project_services_client/spec/*.rb' end rescue Exception => e puts "Problems setting up :test tasks, ingoring #{e.message}" end end # begin # require 'ci/reporter/rake/rspec' # require 'rspec/core/rake_task' # # ENV['CI_REPORTS'] = 'spec-output' # CLEAN.include('spec-output', 'coverage') # # RSpec::Core::RakeTask.new(:api_spec) do |t| # t.pattern = 'p4_web_api/clients/ruby/p4_web_api_client/spec/*.rb' # t.ruby_opts = ["-I#{File.absolute_path('p4_web_api/clients/ruby/p4_web_api_client/spec/lib')}"] # end # task api_spec: 'ci:setup:rspec' # # RSpec::Core::RakeTask.new(:proj_spec) do |t| # t.pattern = 'p4_project_services/clients/ruby/p4_project_services_client/spec/*.rb' # t.ruby_opts = ["-I#{File.absolute_path('p4_project_services/clients/ruby/p4_project_services_client/spec/lib')}"] # end # task proj_spec: 'ci:setup:rspec' # # RSpec::Core::RakeTask.new(:proj_svc_spec) do |t| # t.pattern = 'p4_project_services/p4_project_services/spec/*.rb' # end # task proj_svc_spec: 'ci:setup:rspec' # # rescue LoadError # # no rspec available # end desc 'Rebuild native tools in qt/work directory (please set CMAKE_PREFIX_PATH in environment)' task :qt_build do FileUtils.rmtree('qt/work') if Dir.exist?('qt/work') FileUtils.mkdir('qt/work') system('cd qt/work && cmake .. && make') or fail('qt build failed') end CLEAN.include('qt/work') desc 'Run all qt tests' task :qt_test do system('cd qt/work/p4_phoenix_services_client && ./PhoenixIntegrationTests') or fail('PhoenixIntegrationTests failed') end desc 'Create doc directory from docbook files (requires ant)' directory 'build/doc' => 'docbook' do FileUtils.rmtree('build/doc') if Dir.exist?('build/doc') sh 'cd docbook && ant publicsite -Ddoc.build.path=../tools/p4-doc/manuals/_build && cd ..' end #CLEAN.include('build/doc') # # require 'sequel' # # This use of Rake by Resque, I do not care for. # DB = Sequel.connect('postgres://localhost:4567/notification_services') # # require 'notification_services/workers/webhook_notifier' # require 'resque/tasks' # # namespace :redis do # desc 'Start a local redis-server in work/redis' # task :start do # FileUtils.mkdir_p('work/redis') unless Dir.exist?('work/redis') # pid = Process.spawn('redis-server') # Process.detach(pid) # IO.write('work/redis.pid', pid.to_s) # end # # desc 'Stop the local redis-server' # task :stop do # if File.exist?('work/redis.pid') # pid = IO.read('work/redis.pid').to_i # Process.kill('TERM', pid) # end # end # # desc 'Remove the redis working directory' # task :clean => :stop do # FileUtils.rmtree('work/redis') if Dir.exist?('work/redis') # File.delete('work/redis.pid') if File.exist?('work/redis.pid') # end # end desc 'Archive Qt package in build/ directory' task :publish do if Dir.exist?('build') `chmod -R +w build` end Dir.mkdir('build') unless Dir.exist?('build') ['qt/p4_project_services_client', 'qt/p4_phoenix_services_client'].each do |project| project_name = File.basename(project) puts "Preparing project #{project_name} from #{project}" Dir.glob("#{project}/**/*").each do |file| relative_path = file[(project.length+1)..-1] if File.file?(file) FileUtils.mkdir_p("build/#{project_name}/#{File.dirname(relative_path)}") changelist=`p4 changes -m1 '//web-services/p4ws-main/...#have' | awk '{print $2}'`.strip contents = nil File.open(file, 'rb') do |f| contents = f.read.gsub('DEV', changelist) end File.open("build/#{project_name}/#{relative_path}", 'wb') do |f| f.write(contents) end end end end Dir.glob('') end Rake::PackageTask.new('p4ws', :noversion) do |p| p.need_tar = true #p.need_zip = true p.package_files.include('config/**') p.package_files.include('doc/**') p.package_files.include('docbook/**/*') p.package_files.include('notification_services/**/*') p.package_files.include('p4_phoenix_services/**/*') p.package_files.include('p4_project_services/**/*') p.package_files.include('p4_web_api/**/*') p.package_files.include('p4_web_services_auth/**/*') p.package_files.include('p4init/**/*') p.package_files.include('p4ruby/**/*') p.package_files.include('qt/**/*') p.package_files.include('salt/**/*') p.package_files.include('Gemfile') p.package_files.include('Rakefile') p.package_files.include('README.md') p.package_files.include('Vagrantfile') p.package_files.include('.p4ignore') end CLEAN.include('pkg')