name: PR Code Quality Pipeline
on:
  pull_request:
    branches:
      - develop

env:
  PLUGIN_NAME: ${{ github.event.repository.name }}
  SW_VERSION: 6.4.11.1
  PHP_VERSION: 8.0.0
  NODE_VERSION: 16.13.2

jobs:
  eslint-admin:
      name: ESLint administration
      runs-on: ubuntu-latest
      steps:
        - name: Clone SW development repository
          uses: actions/checkout@v3
          with:
            repository: shopware/development
            ref: trunk

        - name: Clone SW platform repository
          uses: actions/checkout@v3
          with:
            repository: shopware/platform
            ref: v${{ env.SW_VERSION }}
            path: platform

        - name: Clone repository source code
          uses: actions/checkout@v3
          with:
            path: custom/plugins/${{ env.PLUGIN_NAME }}

        - name: Set up PHP ${{ env.PHP_VERSION }}
          uses: shivammathur/setup-php@v2
          with:
            php-version: ${{ env.PHP_VERSION }}

        - name: Set up Node.js ${{ env.NODE_VERSION }}
          uses: actions/setup-node@v3
          with:
            node-version: ${{ env.NODE_VERSION }}

        - name: Install composer dependencies
          run: composer install

        - name: Install ${{ env.PLUGIN_NAME }}
          run: cd custom/plugins/${{ env.PLUGIN_NAME }} && make install -B

        - name: Install Shopware administration NPM dependencies
          run: ./psh.phar administration:install-dependencies

        - name: Run ESLint
          run: cd custom/plugins/${{ env.PLUGIN_NAME }} && make administration-lint -B

  eslint-storefront:
    name: ESLint storefront
    runs-on: ubuntu-latest
    steps:
      - name: Clone SW development repository
        uses: actions/checkout@v3
        with:
          repository: shopware/development
          ref: trunk

      - name: Clone SW platform repository
        uses: actions/checkout@v3
        with:
          repository: shopware/platform
          ref: v${{ env.SW_VERSION }}
          path: platform

      - name: Clone repository source code
        uses: actions/checkout@v3
        with:
          path: custom/plugins/${{ env.PLUGIN_NAME }}

      - name: Set up PHP ${{ env.PHP_VERSION }}
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ env.PHP_VERSION }}

      - name: Set up Node.js ${{ env.NODE_VERSION }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ env.NODE_VERSION }}

      - name: Install composer dependencies
        run: composer install

      - name: Install Shopware storefront NPM dependencies
        run: ./psh.phar storefront:install-dependencies

      - name: Install ${{ env.PLUGIN_NAME }}
        run: cd custom/plugins/${{ env.PLUGIN_NAME }} && make install -B

      - name: Run ESLint
        run: cd custom/plugins/${{ env.PLUGIN_NAME }} && make storefront-lint -B

  ecs:
    name: Easy coding standard
    runs-on: ubuntu-latest
    steps:
      - name: Clone SW development repository
        uses: actions/checkout@v3
        with:
          repository: shopware/development
          ref: trunk

      - name: Clone SW platform repository
        uses: actions/checkout@v3
        with:
          repository: shopware/platform
          ref: v${{ env.SW_VERSION }}
          path: platform

      - name: Clone repository source code
        uses: actions/checkout@v3
        with:
          path: custom/plugins/${{ env.PLUGIN_NAME }}

      - name: Set up PHP ${{ env.PHP_VERSION }}
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ env.PHP_VERSION }}

      - name: Install SW composer dependencies
        run: composer install

      - name: Install dev-ops dependencies
        run: composer install --no-interaction --optimize-autoloader --working-dir=dev-ops/analyze

      - name: Run ECS for project files
        run: cd custom/plugins/${{ env.PLUGIN_NAME }} && make ecs-dry -B

  stylelint-storefront:
    name: StyleLint storefront
    runs-on: ubuntu-latest
    steps:
      - name: Clone SW development repository
        uses: actions/checkout@v3
        with:
          repository: shopware/development
          ref: trunk

      - name: Clone SW platform repository
        uses: actions/checkout@v3
        with:
          repository: shopware/platform
          ref: v${{ env.SW_VERSION }}
          path: platform

      - name: Clone repository source code
        uses: actions/checkout@v3
        with:
          path: custom/plugins/${{ env.PLUGIN_NAME }}

      - name: Set up PHP ${{ env.PHP_VERSION }}
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ env.PHP_VERSION }}

      - name: Set up Node.js ${{ env.NODE_VERSION }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ env.NODE_VERSION }}

      - name: Install ${{ env.PLUGIN_NAME }}
        run: cd custom/plugins/${{ env.PLUGIN_NAME }} && make install -B

      - name: Run Stylelint
        run: cd custom/plugins/${{ env.PLUGIN_NAME }} && make storefront-lint-styles -B 