Skip to content

Instantly share code, notes, and snippets.

@kommen
Created July 17, 2012 16:03
Show Gist options
  • Save kommen/3130297 to your computer and use it in GitHub Desktop.
Save kommen/3130297 to your computer and use it in GitHub Desktop.
Cap task to only precompile rails 3.1 assets if asset files have changed
set :branch, "origin/#{ENV['BRANCH'] || "master"}"
namespace :assets do
desc "Precompile rails 3.1 assets"
task :precompile, :except => { :no_release => true } do
asset_paths = "app/assets lib/assets vendor/assets"
if !ENV['FORCE_PRECOMPILE'].nil? || capture("cd #{current_path}; git diff-tree --name-only -r #{deployed_revision} HEAD #{asset_paths} | wc -l").strip.to_i > 0
deploy.precompile_assets
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end
namespace :deploy do
desc "Update the deployed code."
task :update_code, :except => { :no_release => true } do
run("cat #{current_path}/REVISION") { |c,s,d| set(:deployed_revision, d[0,7]) }
run("cd #{current_path}; git fetch origin; git reset --hard #{branch}; git submodule update --init;echo '#{branch}' > #{current_path}/BRANCH; git rev-parse #{branch} > #{current_path}/REVISION")
end
end
@clemens
Copy link

clemens commented Aug 21, 2012

Now that I actually get to review it, a question: Why are you overriding the update_code task? Couldn't you just use a before/after callback specifically for the git strategy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment