mridang / cpd-annotations
Turns CPD style XML reports into Github pull-request annotations via the Checks API. This script is meant for use within your Github Action.
Fund package maintenance!
mridang
Installs: 1 052
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.0
- ext-simplexml: *
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-11-06 01:48:08 UTC
README
Turns CPD style XML-reports into Github pull-request annotations via the Checks API. This script is meant for use within your Github Action.
That means you no longer have to search through your Github Action log files or the console output. 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.
Images from https://github.com/mheap/phpunit-github-actions-printer
Installation
Install the binary via Composer
composer require mridang/cpd-annotations
Example Usage
cpd2pr
can be used on a already existing CPD-report XML-report. 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:
Process a CPD formatted file
vendor/bin/cpd2pr /path/to/cpd-report.xml
Available Options
--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
Pipe the output of another commmand
This works for any command which produces a CPD-formatted report. Examples can bee seen below:
Using PHCPD
phcpd . xml codesize,naming,unusedcode,controversial,design --exclude libs,var,build,tests --ignore-violations-on-exit | vendor/bin/cpd2pr
Example GithubAction workflow
If you're using shivammathur/setup-php
to setup PHP, cpd2pr
binary is shipped within:
# ... jobs: phcpd-analysis: name: phcpd 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: cpd2pr - run: | composer install # install your apps dependencies vendor/bin/phcpd . xml codesize,naming,unusedcode,controversial,design --exclude libs,var,build,tests --ignore-violations-on-exit | cpd2pr
If you use a custom PHP installation, then your project needs to require mridang/cpd-annotations
# ... jobs: phcpd-analysis: name: phcpd 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 mridang/cpd-annotations # install cpd2pr vendor/bin/phcpd . xml codesize,naming,unusedcode,controversial,design --exclude libs,var,build,tests --ignore-violations-on-exit | vendor/bin/cpd2pr