#!/bin/bash set -ex [[ -z ${HEROKU_APPLICATION} ]] && HEROKU_APPLICATION=$1 [[ ! -s "$(git rev-parse --git-dir)/shallow" ]] || git fetch --unshallow origin if ! git remote | grep heroku then git remote add heroku git@heroku.com:${HEROKU_APPLICATION}.git git fetch heroku fi WORKER_COUNT=$(heroku ps | grep 'worker\.' | wc -l) SCHEDULER_COUNT=$(heroku ps | grep 'scheduler\.' | wc -l) RECEIPTS_COUNT=$(heroku ps | grep 'receipts\.' | wc -l) BLOCKS_COUNT=$(heroku ps | grep 'blocks\.' | wc -l) if ! git diff HEAD heroku/master --exit-code -- priv/repo then if heroku features --app $HEROKU_APPLICATION | grep '\[+\] preboot' then heroku features:disable preboot --app $HEROKU_APPLICATION heroku maintenance:on --app $HEROKU_APPLICATION heroku scale worker=0 scheduler=0 receipts=0 blocks=0 --app $HEROKU_APPLICATION heroku pg:killall --app $HEROKU_APPLICATION git push heroku $CIRCLE_SHA1:refs/heads/master heroku pg:backups capture --app $HEROKU_APPLICATION heroku run "POOL_SIZE=2 mix ecto.migrate" --app $HEROKU_APPLICATION heroku scale worker=${WORKER_COUNT} scheduler=${SCHEDULER_COUNT} receipts=${RECEIPTS_COUNT} blocks=${BLOCKS_COUNT} --app $HEROKU_APPLICATION heroku restart --app $HEROKU_APPLICATION heroku maintenance:off --app $HEROKU_APPLICATION heroku features:enable preboot --app $HEROKU_APPLICATION else heroku maintenance:on --app $HEROKU_APPLICATION heroku scale worker=0 scheduler=0 receipts=0 blocks=0 --app $HEROKU_APPLICATION heroku pg:killall --app $HEROKU_APPLICATION git push heroku $CIRCLE_SHA1:refs/heads/master heroku pg:backups capture --app $HEROKU_APPLICATION heroku run "POOL_SIZE=2 mix ecto.migrate" --app $HEROKU_APPLICATION heroku scale worker=${WORKER_COUNT} scheduler=${SCHEDULER_COUNT} receipts=${RECEIPTS_COUNT} blocks=${BLOCKS_COUNT} --app $HEROKU_APPLICATION heroku restart --app $HEROKU_APPLICATION heroku maintenance:off --app $HEROKU_APPLICATION fi else git push heroku $CIRCLE_SHA1:refs/heads/master heroku pg:backups capture --app $HEROKU_APPLICATION fi