version: 2
jobs:
  build:
    docker:
      - image: circleci/node:latest

    working_directory: ~/cloud-admin-template

    filters:
      branches:
        only: master

    steps:
      - add_ssh_keys:
          fingerprints:
            - "${SSH_KEY}"
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-
      - run: npm set prefix=/home/circleci/npm && echo 'export PATH=$HOME/circleci/npm/bin:$PATH' >> /home/circleci/.bashrc
      - run: npm install

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      - run: git config --global user.name "${CIRCLE_USERNAME}"
      - run: ./deploy.sh
