That means you no longer search thru your GitHub Action logfiles. No need to interpret messages which are formatted differently with every tool. Instead you can focus on your Pull Request, and you don't need to leave the Pull Request area.
Install the binary via composer
composer require staabm/annotate-pull-request-from-checkstyle
cs2pr can be used on a already existing checkstyle-report xml-file. Alternatively you might use it in the unix-pipe notation to chain it into your existing cli command.
Run one of the following commands within your GitHub Action workflow:
--graceful-warnings: Don't exit with error codes if there are only warnings
--colorize: Colorize the output. Useful if the same lint script should be used locally on the command line and remote on GitHub Actions. With this option, errors and warnings are better distinguishable on the command line and the output is still compatible with GitHub Annotations
--notices-as-warningsConverts notices to warnings. This can be useful because GitHub does not annotate notices.
--prepend-filenamePrepend the filename to the output message
--prepend-sourceWhen the checkstyle generating tool provides a
sourceattribute, prepend the source to the output message.
... works for any command which produces a checkstyle-formatted report.
Examples can bee seen below:
phpstan analyse --error-format=checkstyle | cs2pr
Phpstan 0.12.32 introduced native github actions support, therefore you might use this instead:
psalm --output-format=checkstyle | cs2pr
Psalm even supports the required format natively, therefore you might use this instead:
php-cs-fixer fix --dry-run --format=checkstyle | cs2pr
phpcs --report=checkstyle -q /path/to/code | cs2pr
-q option means that no output will be shown in the action logs anymore.
To see the output both in the PR as well as in the action logs, use two steps, like so:
- name: Check PHP code style continue-on-error: true run: phpcs --report-full --report-checkstyle=./phpcs-report.xml - name: Show PHPCS results in PR run: cs2pr ./phpcs-report.xml
Using PHP Parallel Lint
vendor/bin/parallel-lint . --exclude vendor --checkstyle | cs2pr
PHPUnit does not support checkstyle, therefore
cs2pr will not work for you.
you might instead try
If you're using
shivammathur/setup-php to setup PHP,
cs2pr binary is shipped within:
# ... jobs: phpstan-analysis: name: phpstan static code analysis runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup PHP uses: shivammathur/setup-php@v1 with: php-version: 7.3 coverage: none # disable xdebug, pcov tools: cs2pr - run: | composer install # install your apps dependencies vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr
If you use a custom PHP installation, then your project needs to require
# ... jobs: phpstan-analysis: name: phpstan static code analysis runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup PHP run: # custom PHP installation - run: | composer install # install your apps dependencies composer require staabm/annotate-pull-request-from-checkstyle # install cs2pr vendor/bin/phpstan analyse --error-format=checkstyle | vendor/bin/cs2pr
This script is based on a suggestion of Benjamin Eberlei
The Code is inspired by https://github.com/mheap/phpunit-github-actions-printer