lib/heroku_deploy/tasks.rb in heroku_deploy-0.0.5 vs lib/heroku_deploy/tasks.rb in heroku_deploy-0.0.6

- old
+ new

@@ -7,67 +7,85 @@ def heroku_deploy heroku_deploy_tasks.heroku_deploy end end - class HerokuDeploy class Tasks < ::Rake::TaskLib - attr_accessor :heroku_deploy + attr_accessor :heroku_deploy, :staging_app, :production_app - def initialize + def initialize( options = {} ) Rake.application.heroku_deploy_tasks = self + @staging_app = options.delete(:staging_app) + @production_app = options.delete(:production_app) + define end def define namespace :heroku_deploy do desc 'Setup branches and apps on heroku' task :setup => :environment do - puts "I AM THE SETUP TASK!!" + + puts "" + puts "Creating staging branch" + puts "" + `git branch staging` + `git checkout staging` + `git push origin origin:refs/heads/staging` + + puts "" + puts "Creating production branch" + puts "" + `git branch production` + `git checkout production` + `git push origin origin:refs/heads/production` + + `git checkout master` + + puts "" + puts "Creating #{staging_app} Heroku app" + puts "" + `heroku app:create #{staging_app}` + + puts "" + puts "Creating #{production_app} Heroku app" + puts "" + `heroku app:create #{production_app}` + + puts "" + puts "Setup Complete!" + puts "" + end desc 'Deploy changes to staging' task :staging => :environment do - Rake::Task['deploy:backup:staging'].invoke + backup( staging_app ) puts "Deploying to Staging" - puts "Merging staging with master" + merge( "master", "staging" ) - `git checkout master` - `git pull origin master` - `git checkout staging` - `git pull origin staging` - `git merge master` - `git push origin staging` - - heroku_deploy.push_to 'staging' + heroku_deploy.push_to 'staging', staging_app puts "" puts "Staging Deployed!" puts "" end desc 'Deploy changes to production' task :production => :environment do - Rake::Task['deploy:backup:production'].invoke + backup( production_app ) puts "Deploying to Production" - puts "Merging production with staging" + merge( "staging", "production" ) - `git checkout staging` - `git pull origin staging` - `git checkout production` - `git pull origin production` - `git merge staging` - `git push origin production` + heroku_deploy.push_to 'production', production_app - heroku_deploy.push_to 'production' - puts "" puts "Production Deployed!" puts "" end @@ -84,13 +102,21 @@ end end end - def push_to( branch ) + def merge(from_branch, to_branch) + puts "Merging #{from_branch} with #{to_branch}" - app = "grouppay" if branch == "production" - app = "grouppay-staging" if branch == "staging" + `git checkout #{from_branch}` + `git pull origin #{from_branch}` + `git checkout #{to_branch}` + `git pull origin #{to_branch}` + `git merge #{from_branch}` + `git push origin #{to_branch}` + end + + def push_to( branch, app ) puts "Going into maintenance mode" `heroku maintenance:on --app #{app}` \ No newline at end of file