
#
# Circle CI configuration
#
version: 2.1

jobs:

  build:
    working_directory: ~/circulate
    docker:
      - image: node:8.11.2
    steps:
      - checkout
      - restore_cache:
          key: deps-{{ .Branch }}-{{ checksum "package.json" }}
      - run: yarn install
      - run: yarn run build
      - save_cache:
          key: deps-{{ .Branch }}-{{ checksum "package.json" }}
          paths:
            - "node_modules"
      - store_artifacts:
          path: dist/
      - slack/notify:
          channel: circle-ci
          # include_project_field: true
          include_visit_job_action: true
          color: '#e3d756'
          # mentions: 'USERID1,USERID2,'
          message: 🔈Player updated ✅

  deploy:
    working_directory: ~/circulate
    docker:
      - image: node:8.11.2
    steps:
      - checkout
      - run:
          name: update /etc/apt/sources.list for apt-get update
          command: |
            echo "deb http://deb.debian.org/debian jessie main" > /etc/apt/sources.list
            echo "deb http://deb.debian.org/debian stable-updates main" >> /etc/apt/sources.list
      - run: apt-get update && apt-get install -y awscli
      - run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
      - deploy:
          name: "Publish to npmjs"
          command: |
            if [ "${CIRCLE_BRANCH}" == "master" ];then
              yarn install
              cd ./dist/
              npm publish --access public --unsafe-perm
            fi
      - slack/notify:
          channel: circle-ci
          # include_project_field: true
          include_visit_job_action: true
          color: '#e3d756'
          # mentions: 'USERID1,USERID2,'
          message: 🔈Player deployed to production ✅

orbs:
  slack: circleci/slack@3.4.2

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