Nov 07, 2012 by Blake Lucchesi
If your tired of hearing that question asked over and over again then boy do I have the cure for you. Because we use Capistrano to deploy our code (yup! even our PHP projects) I’ve put together this simple task to introspect your git repository and write some details to a tag.txt file. Place that file somewhere that you can access via your website and voilà.
after "deploy:update_code", "deploy:create_tagfile"
desc "Create a tagfile with the latest tag and commit that was deployed."
task :create_tagfile, :roles => :app do
tagfile = "#{current_release}/public/tag.txt"
run "touch #{tagfile}"
run "cd #{current_release}; echo `git describe --tags` >> #{tagfile};"
run "cd #{current_release}; git log -n 1 >> #{tagfile};"
end
And below is a screenshot of the type of info you’ll see in the tag.txt file. (The version number that is output at the top is based on the tag that is attached to the commit.)
You probably don’t want commit messages to be publicly available. As such, I would recommend modifying the snippet above so that you don’t run the task during production deploys. Because that’s a bit environment specific I’ll leave that assignment as your homework.