defaults: &defaults
  docker:
    - image: circleci/node:11.13.0

version: 2
jobs:
  build:
    <<: *defaults
    steps:
      - checkout
      - restore_cache:
          key: dependency-cache-{{ checksum "package.json" }}
      - run:
          name: Install Dependencies
          command: npm ci
      - save_cache:
          key: dependency-cache-{{ checksum "package.json" }}
          paths:
            - node_modules
      - run:
          name: Lint
          command: npm run lint
      - run:
          name: Rollup
          command: npm run rollup
      - run:
          name: CLI
          command: npm run cli
      - persist_to_workspace:
          root: .
          paths:
            - dist
      - persist_to_workspace:
          root: .
          paths:
            - node_modules
  semver:
    <<: *defaults
    steps:
      - checkout
      - attach_workspace:
          at: .
      - run:
          name: Semantic Release
          command: node_modules/.bin/semantic-release

workflows:
  version: 2
  build:
    jobs:
      - build
      - semver:
          requires:
            - build
          filters:
            branches:
              only: master