From be43506e360a3056a9e3a5e013379f1e63ed8773 Mon Sep 17 00:00:00 2001 From: WayneRocha Date: Sun, 28 Jun 2026 23:38:07 -0300 Subject: [PATCH 1/3] fix: skip phpcs when no PHP files changed, handle filenames with spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When CHANGED_FILES is empty (no PHP files in the PR), phpcs was called with no file arguments. Depending on the repo phpcs.xml, this either produced a non-JSON error string (failing jq validation → exit 1) or scanned the entire codebase unintentionally. Also switches from bare variable expansion to xargs so filenames containing spaces are passed as individual arguments rather than being split on whitespace. Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/phpcs.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index 6615b40..412d106 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -48,7 +48,11 @@ jobs: - name: Get list of changed files id: files run: | - echo "CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!tests' | grep '\.php$' | tr '\n' ' ')" >> $GITHUB_ENV + { + echo 'CHANGED_FILES<> $GITHUB_ENV # ------------------------------------------------------------------------------ # PHPCS @@ -60,8 +64,14 @@ jobs: env: REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.access-token }} run: | - # Run phpcs and capture both the output and the exit code - JSON_REPORT=$(vendor/bin/phpcs --report=json -q ${{ env.CHANGED_FILES }} || echo "") + # Skip when no PHP files changed + if [ -z "${{ env.CHANGED_FILES }}" ]; then + echo "No PHP files changed, skipping phpcs" + exit 0 + fi + + # Run phpcs — use xargs so filenames with spaces are handled correctly + JSON_REPORT=$(echo \"${{ env.CHANGED_FILES }}\" | xargs -d '\n' vendor/bin/phpcs --report=json -q) PHPCS_EXIT_CODE=$? # Check if phpcs produced a JSON report From d2afe8565be169e6a5d246ae9a78cbc9b6b4e3ee Mon Sep 17 00:00:00 2001 From: WayneRocha Date: Mon, 29 Jun 2026 12:30:10 -0300 Subject: [PATCH 2/3] fix: skip phpcs when no PHP files changed, handle filenames with spaces - Move changed files detection right after checkout so expensive steps (setup-php, composer-install) are skipped entirely when no PHP files changed - Gate all remaining steps with has_php_files output instead of an early exit inside the shell script - Use printf + xargs -d newline instead of echo with escaped quotes so filenames containing spaces are passed as single arguments to phpcs Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/phpcs.yml | 46 +++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index 412d106..5d58d94 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -29,11 +29,33 @@ jobs: ref: ${{ inputs.ref }} fetch-depth: 0 + # ------------------------------------------------------------------------------ + # Get changed files — runs right after checkout so we can skip remaining + # steps entirely when no PHP files changed + # ------------------------------------------------------------------------------ + - name: Get list of changed files + id: files + run: | + { + echo 'CHANGED_FILES<> $GITHUB_ENV + + if git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!tests' | grep -q '\.php$'; then + echo "has_php_files=true" >> $GITHUB_OUTPUT + else + echo "No PHP files changed, skipping phpcs" + echo "has_php_files=false" >> $GITHUB_OUTPUT + fi + - uses: shivammathur/setup-php@v2 + if: steps.files.outputs.has_php_files == 'true' with: php-version: ${{ inputs.php_version }} - uses: ramsey/composer-install@v3 + if: steps.files.outputs.has_php_files == 'true' with: composer-options: "--ignore-platform-reqs" @@ -42,36 +64,20 @@ jobs: run: | sudo chown -R root:root $GITHUB_WORKSPACE - # ------------------------------------------------------------------------------ - # Get changed files - # ------------------------------------------------------------------------------ - - name: Get list of changed files - id: files - run: | - { - echo 'CHANGED_FILES<> $GITHUB_ENV - # ------------------------------------------------------------------------------ # PHPCS # ------------------------------------------------------------------------------ - uses: reviewdog/action-setup@v1 + if: steps.files.outputs.has_php_files == 'true' with: reviewdog_version: latest # Optional. [latest,nightly,v.X.Y.Z] - name: Run reviewdog + if: steps.files.outputs.has_php_files == 'true' env: REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.access-token }} run: | - # Skip when no PHP files changed - if [ -z "${{ env.CHANGED_FILES }}" ]; then - echo "No PHP files changed, skipping phpcs" - exit 0 - fi - - # Run phpcs — use xargs so filenames with spaces are handled correctly - JSON_REPORT=$(echo \"${{ env.CHANGED_FILES }}\" | xargs -d '\n' vendor/bin/phpcs --report=json -q) + # Run phpcs — printf + xargs -d '\n' keeps filenames with spaces intact + JSON_REPORT=$(printf '%s\n' "${{ env.CHANGED_FILES }}" | xargs -d '\n' vendor/bin/phpcs --report=json -q) PHPCS_EXIT_CODE=$? # Check if phpcs produced a JSON report From f35643632169d2e5b83e3a9753bc484c6851d414 Mon Sep 17 00:00:00 2001 From: Wayne Rocha <62760711+WayneRocha@users.noreply.github.com> Date: Mon, 29 Jun 2026 12:47:03 -0300 Subject: [PATCH 3/3] Update .github/workflows/phpcs.yml Co-authored-by: Volodymyr Shelmuk --- .github/workflows/phpcs.yml | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index 5d58d94..9a5f99e 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -36,18 +36,20 @@ jobs: - name: Get list of changed files id: files run: | - { - echo 'CHANGED_FILES<> $GITHUB_ENV - - if git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!tests' | grep -q '\.php$'; then - echo "has_php_files=true" >> $GITHUB_OUTPUT - else - echo "No PHP files changed, skipping phpcs" - echo "has_php_files=false" >> $GITHUB_OUTPUT - fi + CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!tests' | grep '\.php$' || true) + + { + echo 'CHANGED_FILES<> $GITHUB_ENV + + if [ -n "$CHANGED_FILES" ]; then + echo "has_php_files=true" >> $GITHUB_OUTPUT + else + echo "No PHP files changed, skipping phpcs" + echo "has_php_files=false" >> $GITHUB_OUTPUT + fi - uses: shivammathur/setup-php@v2 if: steps.files.outputs.has_php_files == 'true'