How to verify that a certain deploy of your app was successful? Sure, tests!

You don't have to run the full test suite of your app – it can be a single test with a checklist for your server non-default setup:

  • the upload directory exists and has proper permissions
  • nginx is configured properly to return CORS headers for given URLs

And the easiest way to incorporate tests into deploy routine is to run tests right inside your deploy bash script:

cd /var/www/my-website-working-copy

# call `git fetch`, `composer install` and the rest of your build commands here

set +e
set -e
if [[ ${PHPUNIT_RESULT} =~ FAILURES ]]; then
    echo "Tests FAILED!";
    printf '%s\n' "$PHPUNIT_RESULT";
    # send notification to Slack or email
    exit 1;
    echo "Tests PASSED!"

Do not forget you have to have phpunit installed. Probably your composer install invocation includes --no-dev parameter which prevents installing dev dependencies.

Laravel Forge notes

The script above works perfect inside Laravel Forge.

If the tests fail you will see Forge's generic error message. A button next to this message shows logged output of the deploy script. At the end of this log you will find phpunit output and can guess what went wrong. Anyway "View latest deployment log" button lets you see the same log.

Laravel Forge is configured to exit deploy script on first error. That's why set +e and set -e commands wrap phpunit invocation.

Send notification to Slack

You can use curl to trigger a webhook as seen in Slack docs. But I personally find slacktee command more convenient for such tasks. The snippet below sends PHPUNIT_RESULT to stdout and then sends the same to slacktee.

printf '%s\n' "$PHPUNIT_RESULT" | slacktee -t "Tests FAILED for" -a danger --config ./.slacktee

You might also like this deployment related post: How long your web app is down for deployment?