-
-
Save kjwierenga/381877 to your computer and use it in GitHub Desktop.
Capistrano task to push a deploy tag after deploying a new version.
This file contains 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
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 |
This file contains 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
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