Tagging release before deploying with Capistrano
Thanks to @dunedain289 for a great answer. I took it a step further to try replicate heroku releases for capistrano. I needed a nice tool to know what was already deployed on the servers, and to make a diff with my current local branch:
first, use @dunedain289's code, slightly modified to work for me
task :push_deploy_tag do user = `git config --get user.name`.chomp email = `git config --get user.email`.chomp stage = "production" unless stage # hack, stage undefined for me puts `git tag #{stage}_#{release_name} -m "Deployed by #{user} <#{email}>"` puts `git push --tags origin` end
Add a task to filter the release tags and diff the last
task :diff do stage = "production" unless stage last_stage_tag = `git tag -l #{stage}* | tail -1` system("git diff #{last_stage_tag}", out: $stdout, err: :out) end #this preserves coloring if you have a .gitconfig with [color "diff"] meta = yellow bold frag = magenta bold old = red bold new = green bold
execute
$ cap diff # awesome colored diff of production and local
Just add the short hash of the commit you are building from.
git log -1 --format=%h
I've done something similar with Capistrano. The easiest thing to do is tag using the timestamp name that Capistrano used during the deploy - that's YYYYMMDDHHMMSS, so it's really hard to get duplicates.
Example:
task :push_deploy_tag do
user = `git config --get user.name`.chomp
email = `git config --get user.email`.chomp
puts `git tag #{stage}_#{release_name} #{current_revision} -m "Deployed by #{user} <#{email}>"`
puts `git push --tags origin`
end
Regarding your question in the code about how to output the text via Capistrano. Just change p to puts and it displays fine.