version: 2.1

defaults: &defaults
  working_directory: ~/repo

orbs:
  node: circleci/node@1.1.6
jobs:
  build-and-test:
    <<: *defaults
    executor:
      name: node/default
    steps:
      - checkout
      - node/with-cache:
          steps:
            - run: yarn install
            - run: yarn test
            - persist_to_workspace:
                root: ~/repo
                paths: .
  deploy:
    <<: *defaults
    executor:
      name: node/default
    steps:
      - attach_workspace:
          at: ~/repo
      - run:
          name: Authenticate with registry
          command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/repo/.npmrc
      - run:
          name: Check ENV
          command: echo $NPM_TOKEN
      - run:
          name: Publish Package
          command: npm publish
workflows:
  build-and-test:
    jobs:
      - build-and-test
  deploy:
    jobs:
      - build-and-test:
          filters:
            tags:
              only: /^v.*/
      - deploy:
          requires:
            - build-and-test
          filters:
            tags:
              only: /^v.*/
            branches:
              ignore: /.*/

version: 2.1

defaults: &defaults
  working_directory: ~/repo

orbs:
  node: circleci/node@1.1.6
jobs:
  build-and-test:
    <<: *defaults
    executor:
      name: node/default
    steps:
      - checkout
      - node/with-cache:
          steps:
            - run: yarn install
            - run: yarn test
            - persist_to_workspace:
                root: ~/repo
                paths: .
  deploy:
    <<: *defaults
    executor:
      name: node/default
    steps:
      - attach_workspace:
          at: ~/repo
      - run:
          name: Authenticate with registry
          command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/repo/.npmrc
      - run:
          name: Check ENV
          command: echo $NPM_TOKEN
      - run:
          name: Publish Package
          command: npm publish
workflows:
  build-and-test:
    jobs:
      - build-and-test
  deploy:
    jobs:
      - build-and-test:
          filters:
            tags:
              only: /^v.*/
            branches:
              ignore: /.*/
      - deploy:
          requires:
            - build-and-test
          filters:
            tags:
              only: /^v.*/
            branches:
              ignore: /.*/

Improve filter for deploy job
Improve filter for deploy job
