Skip to content

Instantly share code, notes, and snippets.

@edmundsalvacion
Created September 14, 2012 00:34
Show Gist options
  • Save edmundsalvacion/3718985 to your computer and use it in GitHub Desktop.
Save edmundsalvacion/3718985 to your computer and use it in GitHub Desktop.
%w(app as).each do |role|
desc "Adds #{role} to the target roles for the task"
task(role) do
if ENV['ROLES']
ENV['ROLES'] += ",#{role}"
else
ENV['ROLES'] = role
end
end
end
desc "Executes the task as sudo"
task :use_sudo do
ENV['SUDO'] = '1'
end
namespace :assets 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"
DESC
task :precompile, roles: assets_role, except: { no_release: true } do
from = source.next_revision(current_revision)
cmd = "cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l"
assets_changed = capture(cmd).to_i > 0
if releases.length <= 1 || assets_changed
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