version: 2
defaults: &defaults
  working_directory: ~/bixby-cli
  docker:
    - image: circleci/node
jobs:
  build:
    <<: *defaults  
    steps:
      - checkout
      - run:
          name: install-typescript
          command: sudo npm install -g typescript
      - run:
          name: install-npm-dependencies
          command: npm install
      - run:
          name: build-project
          command: npm run build
  test:
    <<: *defaults
    steps:
      - checkout
      - run:
          name: install-typescript
          command: sudo npm install -g typescript
      - run:
          name: install-npm-dependencies
          command: npm install
      - run:
          name: test
          command: npm test
  deploy:
    <<: *defaults
    steps:
      - checkout
      - run:
          name: install-typescript
          command: sudo npm install -g typescript
      - run:
          name: install-npm-dependencies
          command: npm install
      - run:
          name: build-project
          command: npm run build
      - run:
          name: Set registry URL
          command: npm set registry https://registry.npmjs.org/
      - run:
          name: Authentificate with registry
          command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/bixby-cli/.npmrc
      - run:
          name: Publish package
          command: npm publish --access=public
workflows:
  version: 2
  build-test-deploy:
    jobs:
      - build:
          filters:
            tags:
              only: /^v(\d+\.){2}\d+/   
      - test:
          requires:
            - build
          filters:
            tags:
              only: /^v(\d+\.){2}\d+/
      - deploy:
          requires:
            - test
          filters:
            tags:
              only: /^v(\d+\.){2}\d+/
            branches:
              ignore: /.*/
    
            