machine:
  node:
    version: 6.1.0

dependencies:
  pre:
    - yarn global add lerna codecov
  override:
    - yarn install
    - lerna bootstrap --npm-client=yarn

test:
  override:
    - case $CIRCLE_NODE_INDEX in 0) nvm use 6 && yarn test ;; 1) nvm use 5 && yarn test ;; 2) nvm use 4 && yarn test ;; 3) yarn run lint:flow ;; esac:
        parallel: true

  post:
    - if [[ -e junitresults.xml ]]; then cp junitresults.xml $CIRCLE_TEST_REPORTS/test-results.xml; fi
    - codecov

version: 2

workflows:
  version: 2
  test_n_deploy:
    jobs:
      - test-linter

      - test-node4:
          requires:
            - test-linter
      - test-node6:
          requires:
            - test-linter
      - test-node8:
          requires:
            - test-linter

      - build-docs:
          requires:
            - test-node4
            - test-node6
            - test-node8

jobs:
  test-node4: &test-template
    docker:
      - image: circleci/node:4

    steps:
      - checkout

      - run:
          name: Install build tools
          command: sudo yarn global add codecov

      - restore_cache:
          keys: node-modules-{{ checksum "yarn.lock" }}

      - run:
          name: Install dependencies
          command: |
              yarn install
              yarn run bootstrap

      - save_cache:
          key: node-modules-{{ checksum "yarn.lock" }}
          paths:
              - node_modules

      - run: yarn test

      - run:
          name: Send coverage report
          command: |
              if [ "${NODEJS}" == "4" ]; then
                codecov
              fi

      - store_test_results:
          path: junitresults.xml
          when: on_fail

  test-node6:
    <<: *test-template

    docker:
      - image: circleci/node:6

  test-node8:
    <<: *test-template

    docker:
      - image: circleci/node:8

  test-linter:
    docker:
      - image: circleci/node:latest

    steps:
      - checkout

      - run:
          name: Install build tools
          command: sudo yarn global add codecov

      - restore_cache:
          key: node-modules-{{ checksum "yarn.lock" }}

      - run:
          name: Install dependencies
          command: |
              yarn install
              yarn run bootstrap

      - save_cache:
          key: node-modules-{{ checksum "yarn.lock" }}
          paths:
              - node_modules

      - run: yarn run lint

  build-docs:
    working_directory: ./docs-ng

    docker:
      - image: circleci/python:latest

    steps:
      - run: sudo pip install pipenv

      - restore_cache:
          keys:
            - pipenv-{{ checksum "Pipfile" }}
            - pipenv

      - run: pipenv install

      - save_cache:
          key: pipenv-{{ checksum "Pipfile" }}
          paths:
              - "{{ pipenv --venv }}"

      - run: make html

      - deploy:
          command: |
            if [ "${CIRCLE_BRANCH}" == "master" ]; then
              echo "Deploying docs"
            fi

Add workflow with jobs to CircleCI config
Add workflow with jobs to CircleCI config
