21700: Install Bundler system-wide in Rails postinst
[arvados.git] / services / api / Rakefile
1 #!/usr/bin/env rake
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 # Add your own tasks in files placed in lib/tasks ending in .rake,
7 # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
8
9 require File.expand_path('../config/application', __FILE__)
10 require 'rake/testtask'
11
12 Server::Application.load_tasks
13
14 namespace :test do
15   task(:run).clear
16   # Copied from the definition in Rails 3.2.
17   # This may need to be updated if we upgrade Rails.
18   task :run do
19     errors = %w(test:units test:functionals test:integration test:tasks).collect do |task|
20       begin
21         Rake::Task[task].invoke
22         nil
23       rescue => e
24         { :task => task, :exception => e }
25       end
26     end.compact
27
28     if errors.any?
29       puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n")
30       abort
31     end
32   end
33 end
34
35 namespace :db do
36   namespace :structure do
37     task :dump do
38       require 'tempfile'
39       origfnm = File.expand_path('../db/structure.sql', __FILE__)
40       tmpfnm = Tempfile.new 'structure.sql', File.expand_path('..', origfnm)
41       copyright_done = false
42       started = false
43       begin
44         tmpfile = File.new tmpfnm, 'w'
45         origfile = File.new origfnm
46         origfile.each_line do |line|
47           if !copyright_done
48             if !/Copyright .* Arvados/.match(line)
49                tmpfile.write "-- Copyright (C) The Arvados Authors. All rights reserved.\n--\n-- SPDX-License-Identifier: AGPL-3.0\n\n"
50             end
51             copyright_done = true
52           end
53
54           if !started && /^[^-\n]/ !~ line
55             # Ignore the "PostgreSQL database dump" comment block,
56             # which varies from one client version to the next.
57             next
58           end
59           started = true
60
61           if /^SET (lock_timeout|idle_in_transaction_session_timeout|row_security) = / =~ line
62             # Avoid edit wars between versions that do/don't write (and can/can't execute) this line.
63             next
64           elsif /^COMMENT ON EXTENSION/ =~ line
65             # Avoid warning message when loading:
66             # "structure.sql:22: ERROR:  must be owner of extension plpgsql"
67             tmpfile.write "-- "
68           end
69           tmpfile.write line
70         end
71         origfile.close
72         tmpfile.close
73         File.rename tmpfnm, origfnm
74         tmpfnm = false
75       ensure
76         File.unlink tmpfnm if tmpfnm
77       end
78     end
79   end
80 end
81
82 # Work around Rails3+PostgreSQL9.5 incompatibility (pg_dump used to
83 # accept -i as a no-op, but now it's not accepted at all).
84 module Kernel
85   alias_method :orig_backtick, :`
86   def `(*args) #`#` sorry, parsers
87     args[0].sub!(/\Apg_dump -i /, 'pg_dump ') rescue nil
88     orig_backtick(*args)
89   end
90 end