Skip to content

Instantly share code, notes, and snippets.

@amatsuda
Created November 15, 2012 06:55
Show Gist options
  • Save amatsuda/4077109 to your computer and use it in GitHub Desktop.
Save amatsuda/4077109 to your computer and use it in GitHub Desktop.
perform precompile only when any of the asset files has changed since the last deploy
# do not shallow_clone from Git repo
namespace :deploy do
namespace :assets do
# perform precompile only when any of the asset files has changed since the last deploy
task :precompile, :roles => :web, :except => {:no_release => true} do
from = source.next_revision(current_revision)
asset_changing_files = ['vendor/assets/', 'app/assets/', 'lib/assets', 'Gemfile', 'Gemfile.lock'].select {|f| File.exists? f}
if capture("cd #{latest_release} && #{source.local.log(from)} #{asset_changing_files.join(' ')} | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info 'Skipping asset pre-compilation because there were no asset changes'
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment