version: 2

jobs:
  build:
    docker:
      - image: circleci/php:7.2-node-browsers
    working_directory: ~/laravel-boilerplate
    steps:
      - checkout
      - run: sudo apt install -y libsqlite3-dev zlib1g-dev
      - run: sudo docker-php-ext-install zip
      - run: sudo apt-get install -y libpng-dev
      - run: sudo docker-php-ext-install gd
      - run: sudo composer self-update
      - restore_cache:
          keys:
            - composer-v1-{{ checksum "composer.lock" }}
            - composer-v1-
      - run: composer install -n --prefer-dist
      - save_cache:
          key: composer-v1-{{ checksum "composer.lock" }}
          paths:
            - vendor
      - restore_cache:
          keys:
            - node-v1-{{ checksum "package.json" }}
            - node-v1-
      - run: yarn
      - save_cache:
          key: node-v1-{{ checksum "package.json" }}
          paths:
            - node_modules
      - run: yarn test
      - run: yarn run production
      - run: cp .env.example .env
      - run: php artisan key:generate
      - run: ./vendor/bin/phpunit
