Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,27 @@ jobs:
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.access-token }}
run: |
# Read changed files into array - preserves filenames with spaces, avoids xargs exit code translation
mapfile -t FILES <<< "${{ env.CHANGED_FILES }}"

# Run phpcs - || captures real exit code without letting bash -e kill the step early
PHPCS_EXIT_CODE=0
JSON_REPORT=$(vendor/bin/phpcs --report=json -q "${FILES[@]}") || PHPCS_EXIT_CODE=$?
# phpcs's exit code covers the whole file (incl. pre-existing issues on
# untouched lines), so it must not gate the job. set +e stops bash -e
# from killing the step on that non-zero exit.
set +e
CHECKSTYLE_REPORT=$(vendor/bin/phpcs --report=checkstyle -q "${FILES[@]}")
PHPCS_EXIT_CODE=$?
set -e

# Check if phpcs produced a JSON report
if [ -z "$JSON_REPORT" ]; then
echo "No JSON report generated by phpcs"
exit $PHPCS_EXIT_CODE
# No report + non-zero exit means phpcs itself failed to run.
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

# Validate the JSON
if ! echo "$JSON_REPORT" | jq empty; then
echo "Invalid JSON"
exit 1
fi

# Process JSON and run reviewdog
echo "$JSON_REPORT" | jq -r ' .files | to_entries[] | .key as $path | .value.messages[] as $msg | "\($path):\($msg.line):\($msg.column):`\($msg.source)`<br>\($msg.message)" ' | reviewdog -efm="%f:%l:%c:%m" -name="phpcs" -filter-mode="added" -fail-level=any -reporter=github-pr-review
# reviewdog gates the job: -filter-mode=added + -fail-level=any make it
# exit 1 only for violations on lines this PR changed.
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 with the original phpcs exit code
exit $PHPCS_EXIT_CODE
exit "$REVIEWDOG_EXIT_CODE"