Skip to content

Instantly share code, notes, and snippets.

@cwilby
Created October 27, 2018 19:20
Show Gist options
  • Save cwilby/2892b7cc4c34666a515e24d91a7aba73 to your computer and use it in GitHub Desktop.
Save cwilby/2892b7cc4c34666a515e24d91a7aba73 to your computer and use it in GitHub Desktop.
version: 2
jobs:
build:
docker:
- image: 'cwilby/php7.1-laravel-circleci'
- image: 'circleci/buildpack-deps:latest'
- image: 'circleci/mysql:5.6.38-ram'
- image: 'circleci/node:8.12-browsers'
- image: 'circleci/redis:latest'
steps:
- restore_cache:
keys:
- 'app-{{ .Branch }}-{{ .Revision }}'
- 'app-{{ .Branch }}-'
- 'app-'
- checkout
- save_cache:
key: app-{{ .Branch }}-{{ .Revision }}
paths:
- ".git"
# env setup
- run:
name: 'Setup test environment'
command: |
cp .env.testing .env
chmod -R 777 storage && chmod -R 777 public
echo 127.0.0.1 app.test | sudo tee -a /etc/hosts
mysql -h 127.0.0.1 -u root -e "create database app; create database app_test;"
# composer install
- restore_cache:
keys:
- 'composer-packages-{{ .Branch }}-{{ .Revision }}-'
- 'composer-packages-{{ .Branch }}-'
- run:
name: 'Install Composer packages'
command: 'composer install'
- save_cache:
key: 'composer-packages-{{ .Branch }}-{{ .Revision }}-'
paths:
- ~/.composer/cache
- vendor
# laravel setup
- run:
name: 'Build Laravel app'
command: |
php artisan key:generate
php artisan migrate:fresh --seed
# yarn install
- restore_cache:
keys:
- 'yarn-packages-{{ checksum "yarn.lock" }}'
- run:
name: 'Install NPM dependencies'
command: 'yarn install'
- save_cache:
name: 'Save Yarn cache'
key: 'yarn-packages-{{ checksum "yarn.lock" }}'
paths:
- ~/.cache/yarn
- node_modules
# webpack
- run:
name: 'Compile Vue app'
command: 'yarn run dev'
test:
docker:
- image: 'cwilby/php7.1-laravel-circleci'
- image: 'circleci/mysql:5.6.38-ram'
- image: 'circleci/node:8.12-browsers'
- image: 'circleci/redis:latest'
# php tests
- run:
name: 'Run PHPUnit test suite'
command: |
mkdir -p ~/phpunit
./vendor/bin/phpunit --testdox --log-junit ~/phpunit/junit.xml
when: always
# js tests
- run:
name: 'Run Automated UI tests'
command: |
mkdir -p ~/mocha
./node_modules/mocha/bin/mocha --recursive --reporter mocha-junit-reporter resources/assets/mix/tests/browser
environment:
MOCHA_FILE: mocha/test-results.xml
when: always
- store_test_results:
path: ~/mocha
- store_test_results:
path: ~/phpunit
deploy-stage:
docker:
- image: 'ubuntu:18.04'
steps:
run:
name: Deploy if tests pass and branch is Staging
command: curl https://forge.laravel.com/servers/:server-id/sites/:site-id/deploy/http?token=
deploy-prod:
docker:
- image: 'ubuntu:18.04'
steps:
run:
name: Deploy if tests pass and branch is Master
command: curl https://forge.laravel.com/servers/:server-id/sites/:site-id/deploy/http?token=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment