Skip to content

Commit

Permalink
Fix/ignore phpcs on tests (#6)
Browse files Browse the repository at this point in the history
Fail non silently. Catch phpcs exit code and exit with that one.
  • Loading branch information
dpanta94 committed Jun 18, 2024
2 parents 9fec095 + 804815e commit 7d352a3
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,24 @@ jobs:
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.access-token }}
run: |
vendor/bin/phpcs --report=json ${CHANGED_FILES} | 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-on-error=true -reporter=github-pr-review
# Run phpcs and capture both the output and the exit code
JSON_REPORT=$(vendor/bin/phpcs --report=json ${{ env.CHANGED_FILES }} || echo "")
PHPCS_EXIT_CODE=$?
# Check if phpcs produced a JSON report
if [ -z "$JSON_REPORT" ]; then
echo "No JSON report generated by phpcs"
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-on-error=true -reporter=github-pr-review
# Exit with the original phpcs exit code
exit $PHPCS_EXIT_CODE

0 comments on commit 7d352a3

Please sign in to comment.