Skip to content

Instantly share code, notes, and snippets.

@kjwierenga
Forked from LeipeLeon/ask_for_branch.rb
Created April 28, 2010 08:38
Show Gist options
  • Save kjwierenga/381877 to your computer and use it in GitHub Desktop.
Save kjwierenga/381877 to your computer and use it in GitHub Desktop.
Capistrano task to push a deploy tag after deploying a new version.
set(:branch) do
if :production == stage
branch = Capistrano::CLI.ui.ask("#{`git branch`}\n\nWhich branch do you want to deploy?: ")
raise "Error: The master branch cannot be deployed to production." if 'master' == branch
else
`git branch | grep ^* | sed s/\\*\\ //`.chomp # use current active branch for staging
end
end
namespace :deploy do
after "deploy:restart", "deploy:git:push_deploy_tag"
before "deploy:cleanup", "deploy:git:cleanup_deploy_tag"
namespace :git do
desc "Place release tag into Git and push it to server."
task :push_deploy_tag do
puts `git push origin tag #{rails_env}/#{release_name} #{revision}`
end
desc "Place release tag into Git and push it to server."
task :cleanup_deploy_tag do
count = fetch(:keep_releases, 5).to_i
if count >= releases.length
logger.important "no old release tags to clean up"
else
logger.info "keeping #{count} of #{releases.length} release tags"
tags = (releases - releases.last(count)).map { |release| "#{rails_env}/#{release}" }
tags.each do |tag|
`git push origin :refs/tags/#{tag}`
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment