Skip to content

Instantly share code, notes, and snippets.

@mrpunkin
Created May 25, 2012 16:19
Show Gist options
  • Save mrpunkin/2788999 to your computer and use it in GitHub Desktop.
Save mrpunkin/2788999 to your computer and use it in GitHub Desktop.
after "deploy:finalize_update", "deploy:assets:conditionally_precompile"
namespace :deploy do
namespace :assets do
desc "Remove callback for asset precompiling unless assets were updated based on Git fetch/merge."
task :conditionally_precompile, :roles => assets_role, :except => { :no_release => true } do
updated_assets = capture("cd #{latest_release}; git diff --name-only #{old_commit} #{new_commit}", :except => { :no_release => true }).split.find_all{|fname| File.dirname(fname).match(/^(vendor|app|lib)\/assets/) }
if(updated_assets.empty?)
callback = callbacks[:after].find{|c| c.source == "deploy:assets:precompile" }
callbacks[:after].delete(callback)
logger.info "Skipping asset pre-compilation because there were no asset changes"
else
logger.info("#{updated_assets.length} updated assets. Will precompile.")
end
end
end
end
before "deploy:update_code", "deploy:git:set_old_commit"
before "deploy:finalize_update", "deploy:git:set_new_commit"
set :git_roles, [:app]
namespace :deploy do
namespace :git do
def which_commit(rev="HEAD")
capture("cd #{current_path}; git rev-parse #{rev}", :except => { :no_release => true }).chomp.strip
end
desc "Set variable for commit before update"
task :set_old_commit, :roles => git_roles, :except => { :no_release => true } do
set :old_commit, which_commit
end
desc "Set variable for commit after update"
task :set_new_commit, :roles => git_roles, :except => { :no_release => true} do
set :new_commit, which_commit
end
desc "Update code via git-pull"
task :pull, :roles => git_roles, :except => { :no_release => true} do
run "cd #{current_path}; git pull -q"
end
desc "Update code via git-fetch and reset"
task :fetch, :roles => git_roles, :except => { :no_release => true} do
run "cd #{current_path}; git fetch origin; git reset --hard #{branch}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment