Created
November 26, 2018 01:37
-
-
Save mattgaidica/ab8a87d39a9bff5944359654da9de9ec to your computer and use it in GitHub Desktop.
This file contains hidden or 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 :tddium do | |
| desc "post_build_hook" | |
| task :post_build_hook do | |
| return unless ENV["TDDIUM_MODE"] == "ci" | |
| return unless ENV["TDDIUM_BUILD_STATUS"] == "passed" | |
| dir = File.expand_path("~/.heroku/") | |
| heroku_email = ENV["HEROKU_EMAIL"] | |
| heroku_api_key = ENV["HEROKU_API_KEY"] | |
| current_branch = `git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3-`.strip | |
| abort "invalid current branch" unless current_branch | |
| puts "Current Branch: #{current_branch}" | |
| case current_branch | |
| when 'integration' | |
| app_name = 'matts-api-integration' | |
| when 'staging' | |
| app_name = 'matts-api-staging' | |
| when 'production' | |
| app_name = 'matts-api' | |
| when 'demo' | |
| app_name = 'matts-api-demo' | |
| when 'demo-staging' | |
| app_name = 'matts-api-demo-staging' | |
| when 'pilot' | |
| app_name = 'matts-api-pilot' | |
| when 'pilot-staging' | |
| app_name = 'matts-api-pilot-staging' | |
| end | |
| return unless defined? app_name | |
| puts "App Name: #{app_name}" | |
| push_sha = `git rev-parse HEAD` | |
| push_target = "git@heroku.com:#{app_name}.git" | |
| abort "invalid current branch" unless current_branch | |
| FileUtils.mkdir_p(dir) or abort "Could not create #{dir}" | |
| puts "Writing Heroku Credentials" | |
| File.open(File.join(dir, "credentials"), "w") do |f| | |
| f.write([heroku_email, heroku_api_key].join("\n")) | |
| f.write("\n") | |
| end | |
| File.open(File.expand_path("~/.netrc"), "a+") do |f| | |
| ['api', 'code'].each do |host| | |
| f.puts "machine #{host}.heroku.com" | |
| f.puts " login #{heroku_email}" | |
| f.puts " password #{heroku_api_key}" | |
| end | |
| end | |
| puts "Pushing to Heroku: #{push_target}..." | |
| cmd "git push #{push_target} HEAD:master --force" or abort "could not push to #{push_target}" | |
| puts "Running Heroku Migrations..." | |
| cmd "heroku run rake db:migrate --app #{app_name}" or abort "aborted migrations" | |
| puts "Restarting Heroku..." | |
| cmd "bundle exec heroku restart --app #{app_name}" or abort "aborted heroku restart" | |
| puts "Post Build Complete!" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment