# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2

defaults: &defaults
  working_directory: ~/repo
  docker:
    - image: circleci/node:8.5

jobs:
  build:
    <<: *defaults
    steps:
      - checkout
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          - v1-dependencies-
      - run: npm install
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}
      - run: npm run test
      - store_artifacts:
          path: ~/repo/test-results.xml
      - store_test_results:
          path: ~/repo/test-results.xml

  publish:
    <<: *defaults
    steps:
      - checkout
      # - run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
      - run: npm install
      # - run: npm publish

workflows:
  version: 2
  build_and_test:
    jobs:
      - build
      - publish:
          requires:
            - build
          filters:
            tags:
              only: /v[0-9]+(\.[0-9]+)*/
