Skip to content

ci: skip PHPCS step when a PR changes no PHP files#19

Closed
itsrafsanjani wants to merge 1 commit into
developfrom
fix/wpcs-skip-when-no-php-files
Closed

ci: skip PHPCS step when a PR changes no PHP files#19
itsrafsanjani wants to merge 1 commit into
developfrom
fix/wpcs-skip-when-no-php-files

Conversation

@itsrafsanjani
Copy link
Copy Markdown
Member

@itsrafsanjani itsrafsanjani commented May 21, 2026

Problem

The Inspections workflow fails on PRs that change no PHP files (e.g. PR #18, which only edits readme.txt).

The Detect coding standard violations step builds a list of changed .php files and passes it to phpcs:

vendor/bin/phpcs ${{ steps.changes.outputs.files }} -q --report=checkstyle | cs2pr --graceful-warnings

When the PR touches no PHP files, steps.changes.outputs.files is empty, so phpcs runs with no file arguments. It then falls back to the <file>.</file> directive in phpcs.xml and scans the entire repository, failing on pre-existing violations that have nothing to do with the PR.

Fix

Guard the step with if: steps.changes.outputs.files != '' so it is skipped when there are no PHP files to inspect.

Impact

  • PRs changing no PHP files (readme/asset-only) no longer fail spuriously.
  • PRs that do change PHP files are unaffected — behaviour is identical.

Unblocks #18.

Summary by CodeRabbit

  • Chores
    • Optimized PHP code standard inspection workflow to skip unnecessary checks when no PHP files have been modified.

Review Change Stack

The PHPCS inspection builds a list of changed `.php` files and passes
them to `phpcs`. When a PR touches no PHP files (e.g. a readme-only
change), that list is empty and `phpcs` runs with no file arguments,
falling back to the `<file>.</file>` directive in `phpcs.xml` and
scanning the entire repository -- failing on pre-existing violations
unrelated to the PR.

Guard the step with `if: steps.changes.outputs.files != ''` so it is
skipped when there are no PHP files to inspect.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2c39d6c4-fa11-4f71-9e6d-d4306d5e3a52

📥 Commits

Reviewing files that changed from the base of the PR and between 644fe87 and 50f20fb.

📒 Files selected for processing (1)
  • .github/workflows/wpcs.yml

Walkthrough

The PHPCS workflow step now includes a conditional check to execute only when changed PHP files are detected, avoiding unnecessary tool invocation when the PR modifies only non-PHP assets or documentation.

Changes

Conditional PHPCS Execution

Layer / File(s) Summary
Add PHP file change conditional
.github/workflows/wpcs.yml
The "Detect coding standard violations" step executes only when steps.changes.outputs.files is non-empty, preventing PHPCS from running on commits without PHP file changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A workflow runs smart, not just any day,
When .php files change, then PHPCS at play. 🐇✨
Skip the false alarms, save cycles with care,
Conditional checks keep CI time fair! 🚀

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a conditional skip for the PHPCS step when no PHP files are modified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/wpcs-skip-when-no-php-files

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants