version: 2
jobs:
  build:
    docker:
      - image: circleci/node:8.9.2
    steps:
      - checkout
      - run: npm install
      - add_ssh_keys:
          fingerprints:
            - "c5:21:77:ad:71:12:b2:f3:67:3f:c4:77:37:4d:fb:1a"
      - run:
          name: Run tests
          command: npm run test
      - deploy:
          name: Release module on npm
          command: |
            if [ "${CIRCLE_BRANCH}" == "master" ]; then
              # Write npm token to .npmrc
              echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc

              # Configure git
              git config --global push.default current

              # Remove .gitignore
              rm .gitignore

              # Run Release script
              chmod +x release.sh
              echo "Releasing on Github"
              npm run release
            fi
