Skip to content

localheinz/annotate-pull-request-from-checkstyle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Annotate a Pull Request based on a Checkstyle XML-report

Continuous Integration Continuous Deployment

Turns checkstyle based XML-Reports into Github Pull Request Annotations via the Checks API. This script is meant for use within your GithubAction.

That means you no longer search thru your GithubAction 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.

Logs Example

Context Example Images from https://github.com/mheap/phpunit-github-actions-printer

Installation

Install the binary via composer

composer require staabm/annotate-pull-request-from-checkstyle

Example Usage

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 GithubAction workflow:

Process a checkstyle formatted file

vendor/bin/cs2pr /path/to/checkstyle-report.xml

Pipe the output of another commmand

... works for any command which produces a checkstyle-formatted report.

Examples can bee seen below:

Using PHPStan

phpstan analyse --error-format=checkstyle | vendor/bin/cs2pr

Using Psalm

psalm --output-format=checkstyle | vendor/bin/cs2pr

Psalm even supports the required format natively, therefore you might even use this instead:

psalm --output-format=github
php-cs-fixer --format=checkstyle | vendor/bin/cs2pr
phpcs --report=checkstyle /path/to/code | vendor/bin/cs2pr

phpunit support?

PHPUnit does not support checkstyle, therefore cs2pr will not work for you.

you might instead try

Example GithubAction workflow

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 staabm/annotate-pull-request-from-checkstyle

# ...
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

Resources

GithubAction Problem Matchers

Idea

This script is based on a suggestion of Benjamin Eberlei

The Code is inspired by https://github.com/mheap/phpunit-github-actions-printer

About

Annotate a Github Pull Request based on a Checkstyle XML-report

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%