Last active
August 29, 2015 14:21
-
-
Save jvenezia/06ab8438e6da748118f4 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
HEROKU_APP = ARGV[0] | |
raise 'Heroku application name argument is missing. (e.g. \'ruby lib/tasks/teamcity/heroku/deploy.rb elcurator-staging\')' unless HEROKU_APP | |
HEROKU_GIT_URL = "[email protected]:#{HEROKU_APP}.git" | |
TEMP_DIFF_REMOTE = 'temp_diff_remote' | |
# Check if there is migrations to run | |
puts `git remote add #{TEMP_DIFF_REMOTE} #{HEROKU_GIT_URL}` | |
puts `git fetch #{TEMP_DIFF_REMOTE}` | |
there_is_migrations_to_run = !`git diff HEAD #{TEMP_DIFF_REMOTE}/master db/migrate`.empty? | |
puts `git remote rm #{TEMP_DIFF_REMOTE}` | |
# Push code to heroku app | |
puts `git push #{HEROKU_GIT_URL} master` | |
# Run migrations if needed and restart app | |
if there_is_migrations_to_run | |
puts `heroku maintenance:on -a #{HEROKU_APP}` | |
puts `heroku run rake db:migrate -a #{HEROKU_APP}` | |
puts `heroku restart -a #{HEROKU_APP}` | |
puts `heroku maintenance:off -a #{HEROKU_APP}` | |
else | |
puts `heroku restart -a #{HEROKU_APP}` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment