-
-
Save rsutphin/9010923 to your computer and use it in GitHub Desktop.
| # 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 |
Caveat: this will only work if you have modified capistrano to not use git archive when setting up release directories. If you're using the default cap3 git support, you'll need to find a different way to determine current_revision.
Caveat: this will only work if you have modified capistrano to not use
git archivewhen setting up release directories. If you're using the default cap3 git support, you'll need to find a different way to determinecurrent_revision.
Updated so that this is no longer the case. The current version will work with stock cap3's git integration.
If you have modified how capistrano works with git (for instance, to add git submodule support), you may need to change either the write_revision task or the way :current_revision is determined.
👍 Thanks for this!
Update: As of capistrano 3.2, the git:write_revision task is not necessary — cap now does this itself.
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
Based on a stackoverflow answer for cap2. The cap3 version has to be longer because cap3 doesn't (yet?) have
current_revisionorrelease_name.On the plus side, that means that this task can be run outside a deploy if you prefer.