Skip to content

Instantly share code, notes, and snippets.

@jvenezia
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvenezia/06ab8438e6da748118f4 to your computer and use it in GitHub Desktop.
Save jvenezia/06ab8438e6da748118f4 to your computer and use it in GitHub Desktop.
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 = "git@heroku.com:#{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