Skip to content

Conversation

@dpanta94
Copy link
Member

@dpanta94 dpanta94 commented Jun 18, 2024

Fail non silently. Catch phpcs exit code and exit with that one.

Also check if the json report produced is valid json and if not exit 1

Please ignore the trial and error i had in the branch. Couldn't figure out where it was failing until the only possibility was phpcs 's exit code

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 src/Tribe/Main.php || echo "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
JSON_REPORT=$(vendor/bin/phpcs --report=json src/Tribe/Main.php || echo "")
JSON_REPORT=$(vendor/bin/phpcs --report=json ${CHANGED_FILES} || echo "")

Copy link
Contributor

@redscar redscar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

When the code has issues the PHPCS test fails properly.

When the code has been fixed PHPCS test passes.

Tested on https://github.com/the-events-calendar/events-community/pull/695

@dpanta94 dpanta94 merged commit 7d352a3 into main Jun 18, 2024
@dpanta94 dpanta94 deleted the fix/ignore-phpcs-on-tests branch June 18, 2024 19:49
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.

3 participants