version: 2.1

orbs:
  win: circleci/windows@2.4.0

commands:
  update-yarn:
    steps:
      - run:
          name: Update yarn
          command: yarn global add yarn@latest
  install:
    steps:
      - run:
          name: Install dependencies
          command: yarn install --ignore-engines --frozen-lockfile
  audit:
    steps:
      - run:
          name: Audit dependencies
          command: yarn audit
  build:
    steps:
      - run:
          name: Build packages
          command: yarn build
  lint:
    steps:
      - run:
          name: Lint project
          command: yarn lint
  format:
    steps:
      - run:
          name: Format project
          command: yarn format
  deps:
    steps:
      - run:
          name: Check dependencies
          command: yarn deps
  test:
    steps:
      - run:
          name: Test
          command: yarn test-ci
  save-cache:
    steps:
      - save_cache:
          key: v{{ .Environment.CIRCLE_CACHE_VERSION }}-{{ arch }}-npm-lock-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "yarn.lock" }}
          paths:
            - node_modules
  run-all:
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "yarn.lock" }}
      - update-yarn
      - install
      - save-cache
      - build
      - lint
      - format
      - deps
      - test
  run-tests:
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "yarn.lock" }}
      - update-yarn
      - install
      - save-cache
      - build
      - test
jobs:
  v10:
    docker:
      - image: node:10
    steps:
      - run-tests
  v12:
    docker:
      - image: node:12
    steps:
      - run-all
  v14:
    docker:
      - image: node:14
    steps:
      - run-tests
  windows-v12:
    executor: win/default
    steps:
      - run-tests

workflows:
  node:
    jobs:
      - v10
      - v12
      - v14
      - windows-v12