# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: styletribute/circle-ci-nodejs:v0.5

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-erc721-smartcontract-lib-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-erc721-smartcontract-lib

      - run: yarn install

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-erc721-smartcontract-lib-{{ checksum "package.json" }}
      
      - run:
          name: Npm config
          command: |
            sudo npm install -g npm-cli-login
            NPM_USER=$NPM_USER NPM_PASS=$NPM_PASS NPM_EMAIL=$NPM_EMAIL npm-cli-login
#      - run:
#          name: Build
#          command:  npm test
      - run:
          name: Deploying
          command: |
              CIRCLE_TAG="$(git tag -l --points-at HEAD)" && if [[ $CIRCLE_TAG =~ ^[0-9]+(\.[0-9]+)*$ ]];
              then
                echo $CIRCLE_TAG
                npm publish --tag$CIRCLE_TAG
              else
                echo $CIRCLE_TAG
                echo "Not a release, skipping build"
              fi

workflows:
  version: 2
  build:
    jobs:
      - build:
          filters:
            tags:
              only:
                - /[0-9]+(\.[0-9]+)*/
            branches:
              ignore: /.*/