Skip to content

Instantly share code, notes, and snippets.

@kaichen
Forked from xdite/gist:3072362
Created July 18, 2012 09:03
Show Gist options
  • Save kaichen/3135153 to your computer and use it in GitHub Desktop.
Save kaichen/3135153 to your computer and use it in GitHub Desktop.
deploy/asset.rb
# -*- encoding : utf-8 -*-
set :assets_dependencies, %w(app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb)
namespace :deploy do
namespace :assets do
desc <<-DESC
Run the asset precompilation rake task. You can specify the full path \
to the rake executable by setting the rake variable. You can also \
specify additional environment variables to pass to rake via the \
asset_env variable. The defaults are:
set :rake, "rake"
set :rails_env, "production"
set :asset_env, "RAILS_GROUPS=assets"
set :assets_dependencies, fetch(:assets_dependencies) + %w(config/locales/js)
DESC
task :precompile, :roles => :web, :except => { :no_release => true } do
prev_revision_exists = File.exists?(current_release)
compare_assets_cmd = [
%[cd #{latest_release}],
%[#{source.local.log(source.next_revision(current_revision))} #{assets_dependencies.join ' '} | wc -l]
].join("&&") if prev_revision_exists
if prev_revision_exists && capture(compare_assets_cmd).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