# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2.1

# Used Workspace
workspace: &workspace
  ~/mui

# Config for node
node_config: &node_config
    working_directory: *workspace
    docker:
      - image: circleci/node:8

# Key to cache gradle dependecies
yarn_key: &yarn_key
  yarn-cache-{{ checksum "yarn.lock" }}


jobs:
  install-dependencies:
    <<: *node_config
    steps:
      - checkout
      - attach_workspace:
          at: *workspace
      - restore_cache:
          key: *yarn_key
      - run:
          name: Intal yarn dependencies
          command: yarn
      - save_cache:
          key: *yarn_key
          paths: node_modules
      - persist_to_workspace:
          root: .
          paths: .

  lint:
    <<: *node_config
    steps:
      - attach_workspace:
          at: *workspace
      - run:
          name: Lint
          command: yarn lint

  test:
    <<: *node_config
    steps:
      - attach_workspace:
          at: *workspace
      - run:
          name: Jest
          command: yarn test

  publish:
    <<: *node_config
    steps:
      - attach_workspace:
          at: *workspace
      - run:
          name: Publish
          command: yarn semantic-release


workflows:
  version: 2
  test-and-deploy:
    jobs:
      - install-dependencies
      - lint:
          requires:
              - install-dependencies
      - test:
          requires:
              - install-dependencies
      - publish:
          requires:
              - lint
              - test
          filters:
              branches:
                only: 'master'
