Created
April 28, 2010 07:59
-
-
Save LeipeLeon/381852 to your computer and use it in GitHub Desktop.
Some capistrano tasks (http://wendbaar.nl/blog/2010/04/automagically-tagging-releases-in-github/)
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 branche | |
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 | |
user = `git config --get user.name` | |
email = `git config --get user.email` | |
puts `git tag #{rails_env}_#{release_name} #{revision} -m "Deployed by #{user} <#{email}>"` | |
puts `git push --tags` | |
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 tag -d #{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