bashy's avatar
Level 65

[Tip] Nice bash script to test builds locally

Here's a script I use to test builds locally before pushing (which runs similar tests). If you can see something to improve it, you're welcome to let me know :)

If you use it - enjoy and let me know how it's going!

#!/bin/sh

GRAY='\033[1;30m'
LIGHT_GRAY='\033[0;37m'
CYAN='\033[0;36m'
LIGHT_CYAN='\033[1;36m'
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

abort()
{
    echo >&2 "
${RED}********************
*** BUILD FAILED ***
********************
${NC}"
    exit 1
}

trap 'abort' 0

set -e

# Run some general commands so we're up-to-date
composer self-update
composer install --no-interaction --optimize-autoloader
php artisan config:clear

# Setup DB
#touch database/database.sqlite
#php artisan migrate --database=testing --env=testing

# Start tests
echo >&2 "${CYAN}PHP Lint Test${NC}"
vendor/bin/parallel-lint --exclude vendor --exclude _ide_helper.php .
echo >&2 "${CYAN}PHPMD${NC}"
vendor/bin/phpmd app/ text phpmd.xml
echo >&2 "${CYAN}PHP Fixable PSR2 Issues${NC}"
vendor/bin/phpcbf --standard=psr2 app/
echo >&2 "${CYAN}PHP Coding Standards${NC}"
vendor/bin/phpcs --standard=psr2 --colors app/
echo >&2 "${CYAN}PHPUnit${NC}"
vendor/bin/phpunit

# Remove DB
#echo "" > database/database.sqlite

trap : 0

echo >&2 "
${GREEN}********************
*** BUILD PASSED ***
********************
${NC}"
0 likes
3 replies
ohffs's avatar

Nice! I'll have to have a play with that!

Edit: it'd be really good to be able to 'thumbs up' the first post on a thread. @JeffreyWay any chance for the next re-design? :: flutters eyelashes :: ;-)

martinbean's avatar

@bashy Be interested to hear why you hand-rolled a Bash script instead of using something like Phing—which could be ran both locally and remotely?

bashy's avatar
Level 65

@martinbean Because I enjoy bash scripts and I can do whatever I want to with them!

3 likes

Please or to participate in this conversation.