Skip to content

Instantly share code, notes, and snippets.

@phackwer
Created March 21, 2018 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phackwer/2e80de46fe64cd73dc66ad7ec60ea8eb to your computer and use it in GitHub Desktop.
Save phackwer/2e80de46fe64cd73dc66ad7ec60ea8eb to your computer and use it in GitHub Desktop.
Laravel CI script
#!/bin/sh
alias errcho='>&2 echo'
if [ ! $REPO ]; then
errcho "No \$REPO to clone from;
exit 1;
fi
if [ ! $BRANCH ]; then
errcho "No \$BRANCH to test;
exit 1;
fi
echo "Creating mysql docker container for migrations and seeds test";
docker run \
--name test-db \
-p 33061:3306 \
-e MYSQL_DATABASE=MYSQL_DB \
-e MYSQL_USER=MYSQL_USER \
-e MYSQL_PASSWORD=MYSQL_PASS \
-e MYSQL_ROOT_PASSWORD=MYSQL_PASS \
-e MYSQL_ROOT_HOST="%" \
-d mysql/mysql-server:5.7 \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci
if [ $? > 0 ]; then
errcho "Impossible to create container";
echo "Removing temporary mysql container"
docker stop test-db
docker rm test-db
exit 1;
fi
echo "Getting code from $REPO"
git clone $REPO code
cd code
git checkout $BRANCH
git fetch
git pull origin develop
git merge develop
if [ $? > 0 ]; then
errcho "Impossible to merge";
echo "Removing temporary mysql container"
docker stop test-db
docker rm test-db
cd ../
rm -rf code
exit 1;
fi
echo "Running Composer"
composer install
if [ $? > 0 ]; then
errcho "Impossible to run composer";
echo "Removing temporary mysql container"
docker stop test-db
docker rm test-db
cd ../
rm -rf code
exit 1;
fi
echo "Setting up environment"
echo 'APP_NAME=Laravel
APP_ENV=testing
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33061
DB_DATABASE=MYSQL_DB
DB_USERNAME=root
DB_PASSWORD=MYSQL_PASS
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
FACEBOOK_CLIENT_ID=
FACEBOOK_CLIENT_SECRET=
' > .env
if [ $? > 0 ]; then
errcho "Impossible to create .env file";
echo "Removing temporary mysql container"
docker stop test-db
docker rm test-db
cd ../
rm -rf code
exit 1;
fi
echo "Generating laravel key"
php artisan key:generate
if [ $? > 0 ]; then
errcho "Impossible to run php artisan key:generate";
echo "Removing temporary mysql container"
docker stop test-db
docker rm test-db
cd ../
rm -rf code
exit 1;
fi
echo "Give MySQL container time to spin up properly"
sleep 30
echo "Running migrations"
php artisan migrate
if [ $? > 0 ]; then
errcho "Impossible to run migrations";
echo "Removing temporary mysql container"
docker stop test-db
docker rm test-db
cd ../
rm -rf code
exit 1;
fi
echo "Running seeds"
php artisan db:seed
if [ $? > 0 ]; then
errcho "Impossible to run db:seed";
echo "Removing temporary mysql container"
docker stop test-db
docker rm test-db
cd ../
rm -rf code
exit 1;
fi
echo "Running tests"
php vendor/bin/phpunit -c phpunit.xml
if [ $? > 0 ]; then
errcho "Failed on tests";
echo "Removing temporary mysql container"
docker stop test-db
docker rm test-db
cd ../
rm -rf code
exit 1;
fi
echo "Successfully run CI"
git checkout develop
git merge $BRANCH
git push origin develop
echo "Removing temporary mysql container"
docker stop test-db
docker rm test-db
echo "Removing code"
cd ../
rm -rf code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment