Search code examples
herokudeploymentghost-inspector

Can I abort a Heroku deployment if Ghost Inspector fails?


is it possible to abort a Heroku deployment if the Ghost Inspector tests fail executed with a deploy hook? I know the deploy hook don't wait for answer of a hook but is there any way to achieve this?


Solution

  • You can take advantage of Release phase, which allows you to run any script just before deploying new version of your app.

    First, you need to add line like this to your Procfile

    release: bin/check-ghost-inspector-test
    

    This is assuming that you have bin directory inside your project and executable script check-ghost-inspector-test. This script will be run after app build, config var change, rollback etc. If script returns with status 0, your app will be deployed. Otherwise, release phase will fail and your app won't be deployed.

    Knowing that you should implement the script to poll Ghost Inspector for current status of your test. If test is successful, exit with status 0. If you have a failure, exit with any status other that 0. I guess it is possible to fetch test run status by sending commit sha via some Ghost Inspector api. You have to options to get current commit sha on your dyno:

    1. Enable dyno metadata lab feature by running heroku labs:enable runtime-dyno-metadata -a <app name>. This will inject couple of config vars into your dyno. One of those is HEROKU_SLUG_COMMIT.
    2. Add this buildpack, which will inject SOURCE_VERSION config var.

    The downside of this approach is that you will need to pass some credentials for Ghost Inspector API via config vars.

    The other solution I can think of is to setup some dedicated solution for Continuous Delivery and only invoke new deployment when test are passing.