2014-06-26 21:31:17 +02:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
oldrev, newrev = ARGV
|
|
|
|
|
|
|
|
def run(cmd)
|
2014-08-06 14:47:47 +02:00
|
|
|
exit($CHILD_STATUS.exitstatus) unless system "umask 002 && #{cmd}"
|
2014-06-26 21:31:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
RAILS_ENV = ENV['RAILS_ENV'] || 'production'
|
|
|
|
use_bundler = File.file? 'Gemfile'
|
|
|
|
rake_cmd = use_bundler ? 'bundle exec rake' : 'rake'
|
|
|
|
|
|
|
|
if use_bundler
|
|
|
|
bundler_args = ['--deployment']
|
|
|
|
BUNDLE_WITHOUT = ENV['BUNDLE_WITHOUT'] || 'development:test'
|
|
|
|
bundler_args << '--without' << BUNDLE_WITHOUT unless BUNDLE_WITHOUT.empty?
|
|
|
|
|
|
|
|
# update gem bundle
|
|
|
|
run "bundle install #{bundler_args.join(' ')}"
|
|
|
|
end
|
|
|
|
|
|
|
|
if File.file? 'Rakefile'
|
2014-08-06 14:47:47 +02:00
|
|
|
num_migrations =
|
|
|
|
`git diff #{oldrev} #{newrev} --diff-filter=A --name-only -z db/migrate`
|
|
|
|
.split("\0").size
|
2014-06-26 21:31:17 +02:00
|
|
|
# run migrations if new ones have been added
|
2015-10-31 17:45:44 +01:00
|
|
|
if num_migrations > 0
|
|
|
|
run "#{rake_cmd} db:migrate RAILS_ENV=#{RAILS_ENV}"
|
|
|
|
run "#{rake_cmd} db:migrate RAILS_ENV=#{RAILS_ENV}_be"
|
|
|
|
run "#{rake_cmd} db:migrate RAILS_ENV=#{RAILS_ENV}_ch"
|
2015-12-27 00:09:59 +01:00
|
|
|
run "#{rake_cmd} db:migrate RAILS_ENV=#{RAILS_ENV}_communs"
|
2015-10-31 17:45:44 +01:00
|
|
|
end
|
2014-06-26 21:31:17 +02:00
|
|
|
|
|
|
|
# precompile assets
|
2014-08-06 14:47:47 +02:00
|
|
|
changed_assets = `git diff #{oldrev} #{newrev} --name-only -z app/assets`
|
2014-11-05 21:25:18 +01:00
|
|
|
.split("\0")
|
2014-06-26 21:31:17 +02:00
|
|
|
|
2015-10-31 17:45:44 +01:00
|
|
|
task = 'assets:precompile'
|
2016-02-13 17:24:23 +01:00
|
|
|
unless changed_assets.empty?
|
2015-10-31 17:45:44 +01:00
|
|
|
run "#{rake_cmd} #{task} RAILS_ENV=#{RAILS_ENV} RAILS_GROUPS=assets"
|
|
|
|
end
|
2014-06-26 21:31:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# clear cached assets (unversioned/ignored files)
|
2014-08-06 14:47:47 +02:00
|
|
|
run 'git clean -x -f -- public/stylesheets public/javascripts'
|
2014-06-26 21:31:17 +02:00
|
|
|
|
|
|
|
# clean unversioned files from vendor/plugins (e.g. old submodules)
|
2014-08-06 14:47:47 +02:00
|
|
|
run 'git clean -d -f -- vendor/plugins'
|