name: PHPCS check
on:
  # push:
  pull_request:
  # Allow manually triggering the workflow.
  workflow_dispatch:

# Cancel all previous workflow runs for the same branch that have not yet completed.
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  phpcs:
    name: PHPCS
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Setup PHP
        uses: "shivammathur/setup-php@v2"
        with:
          php-version: "8.2"
          ini-values: "memory_limit=1G"
          coverage: none
          tools: cs2pr
      - name: Install Composer dependencies
        uses: "ramsey/composer-install@v3"
      - name: Run PHPCS checks
        continue-on-error: true
        run: vendor/bin/phpcs --standard=.phpcs.xml --report-full --report-checkstyle=./phpcs-report.xml .
      - name: Show PHPCS results in PR
        run: cs2pr ./phpcs-report.xml
