Skip to content

Instantly share code, notes, and snippets.

@rsutphin
Last active April 18, 2018 13:08
Show Gist options
  • Save rsutphin/9010923 to your computer and use it in GitHub Desktop.
Save rsutphin/9010923 to your computer and use it in GitHub Desktop.
A capistrano 3 task to tag the repo after every deploy
# Requires Capistrano 3.2 or later
namespace :deploy do
after :finishing, :tag_and_push_tag do
on roles(:app) do
within release_path do
set(:current_revision, capture(:cat, 'REVISION'))
# release path may be resolved already or not
resolved_release_path = capture(:pwd, "-P")
set(:release_name, resolved_release_path.split('/').last)
end
end
run_locally do
user = capture(:git, "config --get user.name")
email = capture(:git, "config --get user.email")
tag_msg = "Deployed by #{user} <#{email}> to #{fetch :stage} as #{fetch :release_name}"
tag_name = "#{fetch :stage }-#{fetch :release_name}"
execute :git, %(tag #{tag_name} #{fetch :current_revision} -m "#{tag_msg}")
execute :git, "push --tags origin"
end
end
end
@webhat
Copy link

webhat commented Mar 25, 2014

👍 Thanks for this!

@rsutphin
Copy link
Author

Update: As of capistrano 3.2, the git:write_revision task is not necessary — cap now does this itself.

@glaszig
Copy link

glaszig commented Jan 13, 2015

you should add .strip to user and email. else the tag's message might look a little weird (for me at least, git version 1.9.3 (Apple Git-50)).

Deployed by Jon Doe
 <jon@doe.com>
> to production as 20150113204036

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