version: 2

defaults: &defaults
  docker:
    - image: circleci/node:8.6.0
  working_directory: ~/repo

jobs:
  build:
    <<: *defaults
    dependencies:
      pre:
        - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            - v1-dependencies-
      - run:
          name: NPM Install
          command: npm install
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

  test:
    <<: *defaults
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            - v1-dependencies-
      - run: npm test

workflows:
  version: 2
  build_publish:
    jobs:
      - build
      - test:
          requires:
            - build

version: 2

defaults: &defaults
  docker:
    - image: circleci/node:8.6.0
  working_directory: ~/repo

jobs:
  build:
    <<: *defaults
    dependencies:
      pre:
        - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            - v1-dependencies-
      - run:
          name: NPM Install
          command: npm install
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

  test:
    <<: *defaults
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            - v1-dependencies-
      - run: npm test

  publish:
    <<: *defaults
    steps:
      - checkout
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          - v1-dependencies-
      - run:
          name: Run Semantic Release
          command: npx semantic-release

workflows:
  version: 2
  build_publish:
    jobs:
      - build
      - test:
          requires:
            - build
      - publish:
          requires:
            - test


Add semantic release job for publish to npm
chore: Add semantic release job for publish to npm
