version: 2
aliases:
  - &node_version node:14.17.0

jobs:
  test:
    machine:
      docker_layer_caching: true
    working_directory: ~/cypress-image-diff
    steps:
      - checkout
      - run:
          name: Build docker
          command: make build
      - run:
          name: Run eslint
          command: make lint-test
      - run:
          name: Run unit
          command: make unit-test
      - run:
          name: Run e2e
          command: make e2e-test
      - store-artifacts:
          path: cypress-visual-screenshots
      - store-artifacts:
          path: cypress-visual-report

  build_and_publish:
    docker:
      - image: *node_version
    working_directory: ~/cypress-image-diff
    steps:
      - checkout
      - run: npm install
      - run:
          name: Build
          command: npm run build
      - run:
          name: Publish (semantic release - main only)
          command: ./node_modules/.bin/semantic-release

workflows:
  version: 2
  cypressimagediff:
    jobs:
      - test
      - build_and_publish:
          requires:
            - test
          filters:
            branches:
              only:
                - main
