version: 2
machine:
  services:
    - docker

jobs:
  build:
    docker:
      - image: circleci/node:8.16
    environment:
      - NPM_CONFIG_LOGLEVEL: warn
    working_directory: ~/repo
    steps:
      - checkout
      - setup_remote_docker:
          docker_layer_caching: true
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package-lock.json" }}
      - run:
          name: Installing dependencies
          command: npm install
      - run:
          name: Pruning dependencies
          command: npm prune
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package-lock.json" }}
      - run:
          name: Compiling code
          command: npm run build
      - run:
          name: Testing code
          command: npm run test 
      - run:
          name: Linting code
          command: npm run lint
      - run:
          name: Checking code duplication
          command: npm run duplication
      - deploy:
          name: Semantic release
          command: npm run semantic-release
