Last active
April 18, 2018 13:08
-
-
Save rsutphin/9010923 to your computer and use it in GitHub Desktop.
A capistrano 3 task to tag the repo after every deploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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
<[email protected]>
> to production as 20150113204036
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update: As of capistrano 3.2, the
git:write_revision
task is not necessary — cap now does this itself.