Skip to content

Commit

Permalink
Return heroku run exit code status
Browse files Browse the repository at this point in the history
I noticed that migrations were failing on my deploys but heroku was
still registering it as a successful deploy. It turns out that `heroku
run` does not return the status code from the command you want to run.

Adding `--exit-code` to the `heroku run` commands will correctly return
the status code to the invoker.

Documentation: https://github.com/heroku/heroku-run
  • Loading branch information
jsom committed Apr 1, 2016
1 parent 4f67c6f commit 5b931cc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.38.0

* Successful deploys with failing DB migrations on Heroku bugfix

1.37.0 (March 13, 2016)

* Remove `RAILS_ENV` definitions
Expand Down
4 changes: 2 additions & 2 deletions spec/features/heroku_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
bin_setup_path = "#{project_path}/bin/setup_review_app"
bin_setup = IO.read(bin_setup_path)

expect(bin_setup).to include("heroku run rake db:migrate --app #{app_name}-staging-pr-$1")
expect(bin_setup).to include("heroku run rake db:migrate --exit-code --app #{app_name}-staging-pr-$1")
expect(bin_setup).to include("heroku ps:scale worker=1 --app #{app_name}-staging-pr-$1")
expect(bin_setup).to include("heroku restart --app #{app_name}-staging-pr-$1")
expect(File.stat(bin_setup_path)).to be_executable

bin_deploy_path = "#{project_path}/bin/deploy"
bin_deploy = IO.read(bin_deploy_path)

expect(bin_deploy).to include("heroku run rake db:migrate")
expect(bin_deploy).to include("heroku run rake db:migrate --exit-code")
expect(File.stat(bin_deploy_path)).to be_executable

readme = IO.read("#{project_path}/README.md")
Expand Down
2 changes: 1 addition & 1 deletion templates/bin_deploy
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ branch="$(git symbolic-ref HEAD --short)"
target="${1:-staging}"

git push "$target" "$branch:master"
heroku run rake db:migrate --remote "$target"
heroku run rake db:migrate --exit-code --remote "$target"
heroku restart --remote "$target"
2 changes: 1 addition & 1 deletion templates/bin_setup_review_app.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ heroku pg:backups restore \
DATABASE_URL \
--confirm <%= app_name.dasherize %>-staging-pr-$1 \
--app <%= app_name.dasherize %>-staging-pr-$1
heroku run rake db:migrate --app <%= app_name.dasherize %>-staging-pr-$1
heroku run rake db:migrate --exit-code --app <%= app_name.dasherize %>-staging-pr-$1
heroku ps:scale worker=1 --app <%= app_name.dasherize %>-staging-pr-$1
heroku restart --app <%= app_name.dasherize %>-staging-pr-$1

0 comments on commit 5b931cc

Please sign in to comment.