fix: use mapfile array instead of xargs to preserve real phpcs exit code#23
Merged
Conversation
xargs translates phpcs exit code 1 (violations found) to exit code 123. GitHub Actions runs steps with bash -e, so when xargs returns 123 the step dies immediately - reviewdog never runs and no inline comments are posted. Using mapfile to read CHANGED_FILES into a bash array gives us the real phpcs exit code and || prevents bash -e from killing the step early.
Contributor
Author
redscar
approved these changes
Jul 1, 2026
dpanta94
approved these changes
Jul 1, 2026
WayneRocha
added a commit
that referenced
this pull request
Jul 2, 2026
…de (#24) ## Problem After #22 and #23, the phpcs job still fails on PRs that introduce **no new violations**. The `Run reviewdog` step ends with: ```bash exit $PHPCS_EXIT_CODE ``` So the job's pass/fail is driven by **phpcs's** exit code. But phpcs scans the whole changed file, so its exit code reflects **every** issue in that file — including pre-existing ones on lines the PR never touched. `reviewdog`, by contrast, runs with `-filter-mode=added` and only reports/fails on issues introduced on the PR's **added lines**. The two disagree, and the job exits on the phpcs code. ### Reproduction — the-events-calendar#5687 "clean" test (`bf090fc`) From the job log: ``` mapfile -t FILES <<< "src/functions/views/provider.php" ##[error]Process completed with exit code 2. ``` - phpcs scanned `provider.php`, found pre-existing issues → exited **2**. - Those issues are **not** on the PR's added lines, so reviewdog filtered them out → **no inline comment** ("No bot display"). - Then `exit $PHPCS_EXIT_CODE` ran `exit 2` → **job failed anyway**. `#22`/`#23` focused on faithfully *preserving* the phpcs exit code — which is exactly the value that should **not** gate the job. ## Fix - Run phpcs with `--report=checkstyle` and pipe straight to reviewdog (`-f=checkstyle`), dropping the `jq` transform. - **Exit with reviewdog's exit code, not phpcs's.** `-filter-mode=added -fail-level=any` means reviewdog exits `1` only when it reports a violation on a line this PR changed. - Keep a guard: if phpcs produces **no** checkstyle output *and* exits non-zero, it genuinely failed to run (bad standard, parse error, …) → fail the job with phpcs's code. ```bash set +e CHECKSTYLE_REPORT=$(vendor/bin/phpcs --report=checkstyle -q "${FILES[@]}") PHPCS_EXIT_CODE=$? set -e if [ -z "$CHECKSTYLE_REPORT" ] && [ "$PHPCS_EXIT_CODE" -ne 0 ]; then echo "phpcs failed to run (exit code $PHPCS_EXIT_CODE)" exit "$PHPCS_EXIT_CODE" fi REVIEWDOG_EXIT_CODE=0 echo "$CHECKSTYLE_REPORT" \ | reviewdog -f=checkstyle -name="phpcs" -filter-mode="added" -fail-level=any -reporter=github-pr-review \ || REVIEWDOG_EXIT_CODE=$? exit "$REVIEWDOG_EXIT_CODE" ``` ## Expected behavior across the-events-calendar#5687 test commits | Commit | Introduces new violations? | reviewdog comment | Job | |---|---|---|---| | Test 1 / Test 2 | yes | posted | **fails** ✅ | | Test 3 (clean) | no (pre-existing only) | none | **passes** ✅ | ## Test PR the-events-calendar#5687 repointed to `@fix/phpcs-reviewdog-exit-code` to re-run all three scenarios. Created by claude 🤖
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
After #22 merged, phpcs CI still fails incorrectly when violations are found.
xargstranslates phpcs exit code1(violations found) into exit code123. GitHub Actions runs steps withbash -eby default, so whenxargsreturns123the step dies immediately — reviewdog never runs, no inline comments are posted, and the job fails with a cryptic exit code instead of the actual violations.Practical impact:
Fix
Replace
printf | xargswithmapfileto readCHANGED_FILESinto a bash array. This:|| PHPCS_EXIT_CODE=$?to preventbash -efrom killing the step before reviewdog runsTest PRs
All affected repos have test PRs pointing to
fix/phpcs-xargs-exit-code(updated from #22 test PRs).Examples
the-events-calendar/the-events-calendar#5676
the-events-calendar/tribe-common#2939
the-events-calendar/event-tickets#4280
More in #22