version: 2.1
orbs:
  node: circleci/node@4.7.0
jobs:
  build-and-test:
    executor: node/default
    steps:
      - checkout
      - restore_cache:
          name: Restore Yarn Package Cache
          keys:
            - yarn-packages-{{ checksum "yarn.lock" }}
      - run:
          name:  📦 Install packages
          command: yarn install --frozen-lockfile --cache-folder ~/.cache/yarn --ignore-engines
      - save_cache:
          name: Save Yarn Package Cache
          key: yarn-packages-{{ checksum "yarn.lock" }}
          paths:
            - ~/.cache/yarn
      - run:
          name:  🧹 Linting
          command: yarn lint
      - run:
          name:  🧪 Testing
          command: yarn test
  publish:
    executor:
      name: node/default
    steps:
      - checkout
      - run:
          name:  📦 Install packages
          command: yarn install
      - run:
          name:  🚧 Building
          command: yarn build
      - run: 
          name: 🚀 Publish to Github Package
          command: yarn semantic-release || true

workflows:
    build-and-test:
      jobs:
        - build-and-test
        - publish: 
            requires:
              - build-and-test
            filters:
              branches:
                only: master