executor: node

parameters:
  cache-version:
    type: string
  path:
    type: string
    default: .

steps:
  - checkout
  - restore-cache:
      version: << parameters.cache-version >>
      cache-name: dependencies
  - attach_workspace:
      at: .
  - run:
      name: Send snapshots to Chromatic
      command: |
        if [[ "${CIRCLE_BRANCH}" != "master" && "${CIRCLE_BRANCH}" != "main" && "${CIRCLE_BRANCH}" != "feature-branch/"* ]]; then
          yarn --cwd << parameters.path >> run chromatic test --exit-zero-on-changes --storybook-build-dir=storybook-static --exit-once-uploaded
        else
          yarn --cwd << parameters.path >> run chromatic test --exit-zero-on-changes --storybook-build-dir=storybook-static --exit-once-uploaded --auto-accept-changes
        fi
