version: 2
jobs:
  build:
    docker:
      - image: circleci/node:8
    steps:
      - checkout
      - restore_cache:
          name: Restore Yarn Package Cache
          keys:
            - yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }}
            - yarn-packages-{{ .Branch }}
            - yarn-packages-master
            - yarn-packages-
      - run:
          name: Prepare Greenkeeper
          command: |
            echo 'export PATH=$(yarn global bin):$PATH' >> "$BASH_ENV"
            source "$BASH_ENV"
            yarn global add greenkeeper-lockfile@1
      - run:
          name: Install Dependencies
          command: yarn install
      - save_cache:
          name: Save Yarn Package Cache
          key: yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }}
          paths:
            - node_modules/
            - ~/.yarn/bin/
            - ~/.config/yarn/global/
            - ~/.cache/yarn
      - run: greenkeeper-lockfile-update
      - run: yarn test
      - run: greenkeeper-lockfile-upload
