Skip to content

Instantly share code, notes, and snippets.

@dtaniwaki
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save dtaniwaki/9542915 to your computer and use it in GitHub Desktop.

Select an option

Save dtaniwaki/9542915 to your computer and use it in GitHub Desktop.
Skip assets:precompile only if the assets are updated.
def do_if_updated(tag, *sources, &block)
to = (latest_revision rescue nil)
from = (current_revision rescue nil)
doit = if !from || !to || !fetch(:smart_assets_precompile, true)
true
else
run_locally("#{source.local.log(from, to)} #{sources.join(' ')} | wc -l").to_i > 0
end
if doit
block.call
else
logger.important "Skipping [#{tag}] because there was no change in #{sources.join(' ')} between #{from} and #{to}"
end
end
namespace :assets do
task :precompile, roles: :app do
do_if_updated("assets precompile", "vendor/assets/", "app/assets/", "lib/assets/", "config") do
run %Q{cd #{current_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment