lib/pah/files/lib/tasks/integration.rake in pah-0.0.9 vs lib/pah/files/lib/tasks/integration.rake in pah-0.0.10

- old
+ new

@@ -2,12 +2,50 @@ def run_with_clean_env(command, capture_output=false) Bundler.with_clean_env { capture_output ? `#{command}` : sh(command) } end +def confirm(message) + print "\n#{message}\nAre you sure? [yN] " + raise 'Ok. Bye...' unless STDIN.gets.chomp.downcase == 'y' +end + +def has_database?(app) + database_url = run_with_clean_env("heroku config -s --app #{app} | grep DATABASE_URL", true).strip + not database_url.blank? +end + +def backup(app) + return unless has_database?(app) + puts "--> Backing up database via Heroku".magenta + run_with_clean_env("heroku pgbackups:capture --expire --app #{app}") +end + +def migrate(app) + return unless has_database?(app) + puts "--> Migrating".magenta + run_with_clean_env("heroku run rake db:migrate --app #{app}") +end + +def seed(app) + return unless has_database?(app) + puts "--> Seeding".magenta + run_with_clean_env("heroku run rake db:seed --app #{app}") +end + +def restart(app) + puts "--> Restarting".magenta + run_with_clean_env("heroku restart --app #{app}") +end + +def deploy(app) + puts "--> Pushing".magenta + run_with_clean_env("git push git@heroku.com:#{APP}.git HEAD:master") +end + namespace :integration do - APP = ENV['STAGING_APP'] || ENV['APP'] + APP = 'PROJECT' USER = run_with_clean_env("git config --get user.name", true).strip namespace :heroku do desc "Add Heroku git remotes" @@ -42,10 +80,19 @@ desc "Unlock the Heroku integration" task :unlock do puts "--> Unlocking Heroku integration".magenta run_with_clean_env("heroku config:unset INTEGRATING_BY --app #{APP}") end + + desc "Deploy to heroku" + task :deploy do + backup(APP) + deploy(APP) + migrate(APP) + seed(APP) + restart(APP) + end end end INTEGRATION_TASKS = %w( integration:heroku:add_remote @@ -55,8 +102,8 @@ integration:bundle_install db:migrate spec integration:coverage_verify integration:finish - heroku:deploy:staging + integration:heroku:deploy integration:heroku:unlock )