
version: 2

defaults: &defaults
  working_directory: ~/standardly
  docker:
    - image: circleci/node:latest-browsers

jobs:
  install:
    <<: *defaults
    steps:
      - checkout
      - restore_cache:
          keys:
            # Find a cache corresponding to this specific package.json checksum
            # when this file is changed, this key will fail
            - standardly-{{ .Branch }}-{{ checksum "package-lock.json" }}-{{ checksum ".circleci/config.yml" }}
            - standardly-{{ .Branch }}-{{ checksum "package-lock.json" }}
            - standardly-{{ .Branch }}
            # Find the most recent cache used from any branch
            - standardly-master
            - standardly-
      - run:
          name: Install Dependencies
          command: yarn install --frozen-lockfile
      - save_cache:
          key: standardly-{{ .Branch }}-{{ checksum "package-lock.json" }}-{{ checksum ".circleci/config.yml" }}
          paths:
            - node_modules
            - ~/.cache/yarn
      - persist_to_workspace:
          root: .
          paths:
            - .

  test:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/standardly
      - run:
          name: Test
          command: yarn test

  lint:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/standardly
      - run:
          name: Lint
          command: yarn lint

  # integration:
  #   <<: *defaults
  #   steps:
  #     - attach_workspace:
  #         at: ~/standardly
  #     - run:
  #         name: Integration Tests
  #         command: yarn test:integration

  release:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/standardly
      - run: mkdir ~/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
      - run:
          name: Release
          command: yarn release

workflows:
  version: 2
  build_and_test:
    jobs:
      - install
    
      - test:
          requires:
            - install

      - lint:
          requires:
            - install

      # - integration:
      #     requires:
      #       - install
    
      - release:
          requires:
            - lint
            - test
            # - integration
    
