Skip to content

Commit

Permalink
Refs #3 - supports branch name change
Browse files Browse the repository at this point in the history
  • Loading branch information
zac23or committed Oct 28, 2016
1 parent c2e3167 commit ee7d6fc
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions lib/tasks/integrate.rake
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ task integrate: [
'integration:git:pull',
'integration:bundle_install',
'integration:test',
'integration:git:master_branch_check',
'integration:git:promote_master_to_staging',
'integration:git:development_branch_check',
'integration:git:promote_development_to_staging',
'integration:git:push',
'integration:lock',
'integration:deploy',
Expand All @@ -40,7 +40,7 @@ task promote_staging_to_production: [
'integration:git:status_check',
'integration:clear_before_pull',
'integration:git:pull',
'integration:git:master_branch_check',
'integration:git:development_branch_check',
'integration:git:promote_staging_to_production',
'integration:git:push',
'integration:db:backup',
Expand All @@ -50,6 +50,10 @@ task promote_staging_to_production: [
]

namespace :integration do
BRANCH_DEVELOPMENT = env['INTEGRATE_BRANCH_DEVELOPMENT'] || 'master'
BRANCH_STAGING = env['INTEGRATE_BRANCH_STAGING'] || 'staging'
BRANCH_PRODUCTION = env['INTEGRATE_BRANCH_PRODUCTION'] || 'production'

task :set_production_as_deploy_env do
ENV['APP_ENV'] ||= 'production'
end
Expand Down Expand Up @@ -83,7 +87,7 @@ namespace :integration do

task 'deploy' do
puts "-----> Pushing #{APP_ENV} to #{APP}..."
sh_with_clean_env "git push [email protected]:#{APP}.git #{APP_ENV}:master"
sh_with_clean_env "git push [email protected]:#{APP}.git #{APP_ENV}:#{BRANCH_DEVELOPMENT}"

puts "-----> Migrating..."
sh_with_clean_env "heroku run rake db:migrate --app #{APP}"
Expand Down Expand Up @@ -121,7 +125,7 @@ namespace :integration do
end
end

task 'master_branch_check' do
task 'development_branch_check' do
cmd = []
cmd << "git branch --color=never" # list branches avoiding color
# control characters
Expand All @@ -131,10 +135,10 @@ namespace :integration do
branch = `#{cmd.join('|')}`.chomp

# Don't use == because git uses bash color escape sequences
unless branch == 'master'
unless branch == BRANCH_DEVELOPMENT
puts "You are at branch <#{branch}>"
puts "Integration deploy runs only from <master> branch," +
" please merge <#{branch}> into <master> and" +
puts "Integration deploy runs only from <#{BRANCH_DEVELOPMENT}> branch," +
" please merge <#{branch}> into <#{BRANCH_DEVELOPMENT}> and" +
" run integration proccess from there."

exit
Expand All @@ -149,20 +153,20 @@ namespace :integration do
sh 'git push'
end

task :promote_master_to_staging do
sh "git checkout staging"
task :promote_development_to_staging do
sh "git checkout #{BRANCH_STAGING}"
sh 'git pull --rebase'
sh "git rebase master"
sh 'git push origin staging'
sh "git checkout master"
sh "git rebase #{BRANCH_DEVELOPMENT}"
sh 'git push origin #{BRANCH_STAGING}'
sh "git checkout #{BRANCH_DEVELOPMENT}"
end

task :promote_staging_to_production do
sh "git checkout production"
sh "git checkout #{BRANCH_PRODUCTION}"
sh 'git pull --rebase'
sh "git rebase staging"
sh 'git push origin production'
sh "git checkout master"
sh "git rebase #{BRANCH_STAGING}"
sh 'git push origin #{BRANCH_PRODUCTION}'
sh "git checkout #{BRANCH_DEVELOPMENT}"
end
end
end

0 comments on commit ee7d6fc

Please sign in to comment.