version: 2
jobs:
  install:
    macos:
      xcode: "11.2.1"
    working_directory: ~/repo
    steps:
      - checkout
      - restore_cache:
          key: cache-{{ checksum "yarn.lock" }}
      - run:
          name: Installing Dependencies
          command: yarn --ignore-engines
      - save_cache:
          key: cache-{{ checksum "yarn.lock" }}
          paths:
            - node_modules
      - run:
          name: Getting build icon
          command: if [[ $CIRCLE_BRANCH == canary ]]; then cp build/canary.icns build/icon.icns; fi
      - persist_to_workspace:
          root: .
          paths:
            - node_modules
            - app/node_modules

  test:
    macos:
      xcode: "11.2.1"
    steps:
      - checkout
      - attach_workspace:
          at: .
      - run:
          name: Testing
          command: yarn test

  build:
    macos:
      xcode: "11.2.1"
    steps:
      - checkout
      - attach_workspace:
          at: .
      - run:
          name: Building
          command: yarn dist --publish 'never'
      - store_artifacts:
          path: dist
      - persist_to_workspace:
          root: .
          paths:
            - dist

  release:
    macos:
      xcode: "11.2.1"
    steps:
      - checkout
      - attach_workspace:
          at: .
      - run:
          name: Deploying to GitHub
          command: yarn dist


workflows:
  version: 2
  build:
    jobs:
      - install:
          filters:
            tags:
              only: /.*/
      - test:
          requires:
            - install
          filters:
            tags:
              only: /.*/
      - build:
          requires:
            - test
          filters:
            branches:
              only:
                - master
                - canary
            tags:
              ignore: /.*/
      - release:
          requires:
            - test
          filters:
            tags:
              only: /.*/
            branches:
              ignore: /.*/
