name: Cypress component testing

on:
  pull_request:
    branches:
      - master
      - dev

concurrency:
  # New commit on branch cancels running workflows of the same branch
  group: ${{ github.workflow }}-${{ github.head_ref }}
  cancel-in-progress: true

jobs:
  state:
    # cypress checks for "release branch" run in cypress-release-branch.yml file
    if: ${{ !startsWith(github.head_ref, 'release') }}
    uses: ./.github/workflows/change-detection.yml
    secrets: inherit

  cypress:
    needs: state
    if: ${{ fromJSON(needs.state.outputs.STATE).HAS_PACKAGES_CYPRESS_RUN }}
    strategy:
      fail-fast: false
      matrix:
        # [Note]
        # Важно что бы массив был со значениями, где `""` экранируются, например -> ["\"b2c\""]
        # Можно для этого использовать JSON.stringify()
        scope: ${{ fromJson(needs.state.outputs.STATE).PACKAGES_CYPRESS_RUN }}

    uses: ./.github/workflows/cypress-common.yml
    with:
      scope: ${{ matrix.scope }}
    secrets: inherit

  cypress-react-17:
    needs: state
    if: ${{ fromJSON(needs.state.outputs.STATE).HAS_PACKAGES_CYPRESS_RUN }}
    strategy:
      fail-fast: false
      matrix:
        scope: ${{ fromJson(needs.state.outputs.STATE).PACKAGES_CYPRESS_RUN }}

    uses: ./.github/workflows/cypress-common.yml
    with:
      scope: ${{ matrix.scope }}
      with-react-17: true
    secrets: inherit