How to write out the deployed git revision to a file in Capistrano

I use Capistrano to deploy my rails app. How can I write out the git revision being deployed to public_html/revision.txt?

Answers


You can get the latest commit ID with the log command and then redirect it to your file:

git --no-pager log -1 --pretty=format:%H > public_html/revision.txt

In case anyone else has to do this:

namespace :deploy do
  # ...

  desc "Write the current version to public_html/revision.txt"
  task :write_revision, :except => { :no_release => true } do
    run "cd #{latest_release}; git rev-parse HEAD > #{latest_release}/public/revision.txt"
  end

  # ...
end

after "deploy:update_code", "deploy:write_revision"

Need Your Help

Eclipse CDT indexer lost after system update

linux eclipse ubuntu eclipse-cdt cdt

I am using Eclipse on Ubuntu for C++ development. After updating from Ubuntu 11.04 to Ubuntu 11.10, Eclipse indexer no longer is able to find my C/C++ system headers and annoys me filling the whole

Filtering across two ManyToMany fields

mysql django orm

I have a User model and an Event model. I have the following for both:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.