name: Drupal coding standards

on:
  # Run on all pushes and on all pull requests.
  # Prevent the build from running when there are only irrelevant changes.
  push:
    paths-ignore:
      - '**.md'
  pull_request:
    paths-ignore:
      - '**.md'
  # Allow manually triggering the workflow.
  workflow_dispatch:

jobs:
  Verify:
    name: "Verify Drupal coding standards"

    runs-on: "ubuntu-latest"

    env:
      PHP_VERSION: "7.4"
      CODE_SNIFFER_PATH: "droopler.* src/ modules/custom/ themes/custom/"
      CODE_SNIFFER_IGNORE: "*md,*.css,*.txt,*.info,*interactive_ui/react_slider/js*,*pl-sk/*,*pattern-lab/*,*_twig-components/*"
      CODE_SNIFFER_EXTENSIONS: "php,inc,install,module,yaml,yml,theme,profile"

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Install PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ env.PHP_VERSION }}
          coverage: none
          tools: composer, phpcs

      - name: Allow phpcs composer installer
        run: composer config --global --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true

      - name: Download Drupal coding standards
        run: composer global require --no-progress --no-suggest --no-scripts --no-plugins --optimize-autoloader slevomat/coding-standard:^7.0 drupal/coder

      - name: Add Drupal coding standards to phpcs
        run: phpcs --config-set installed_paths $HOME/.composer/vendor/drupal/coder/coder_sniffer,$HOME/.composer/vendor/slevomat/coding-standard

      - name: Verify coding standards
        run: phpcs ${{ env.CODE_SNIFFER_PATH }} --ignore=${{ env.CODE_SNIFFER_IGNORE }} --extensions=${{ env.CODE_SNIFFER_EXTENSIONS}} --standard=Drupal --report=full,gitblame

