PHPackages                             staabm/annotate-pull-request-from-checkstyle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. staabm/annotate-pull-request-from-checkstyle

ActiveLibrary[Testing &amp; Quality](/categories/testing)

staabm/annotate-pull-request-from-checkstyle
============================================

1.8.6(8mo ago)2013.4M—8.3%26[3 issues](https://github.com/staabm/annotate-pull-request-from-checkstyle/issues)[2 PRs](https://github.com/staabm/annotate-pull-request-from-checkstyle/pulls)20MITPHPPHP ^5.3 || ^7.0 || ^8.0CI passing

Since Jan 23Pushed 2mo ago5 watchersCompare

[ Source](https://github.com/staabm/annotate-pull-request-from-checkstyle)[ Packagist](https://packagist.org/packages/staabm/annotate-pull-request-from-checkstyle)[ GitHub Sponsors](https://github.com/staabm)[ RSS](/packages/staabm-annotate-pull-request-from-checkstyle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (25)Used By (20)

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

[](#annotate-a-pull-request-based-on-a-checkstyle-xml-report)

[![Continuous Integration](https://github.com/staabm/annotate-pull-request-from-checkstyle/workflows/Continuous%20Integration/badge.svg)](https://github.com/staabm/annotate-pull-request-from-checkstyle/actions)[![Continuous Deployment](https://github.com/staabm/annotate-pull-request-from-checkstyle/workflows/Continuous%20Deployment/badge.svg)](https://github.com/staabm/annotate-pull-request-from-checkstyle/actions)

Turns [checkstyle based XML-Reports](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v3.0.2/doc/schemas/fix/checkstyle.xsd) into GitHub Pull Request [Annotations via the Checks API](https://docs.github.com/en/free-pro-team@latest/rest/reference/checks). This script is meant for use within your GitHub Action.

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.

[![Logs Example](https://github.com/mheap/phpunit-github-actions-printer/raw/master/phpunit-printer-logs.png?raw=true)](https://github.com/mheap/phpunit-github-actions-printer/blob/master/phpunit-printer-logs.png?raw=true)

[![Context Example](https://github.com/mheap/phpunit-github-actions-printer/raw/master/phpunit-printer-context.png?raw=true)](https://github.com/mheap/phpunit-github-actions-printer/blob/master/phpunit-printer-context.png?raw=true)*Images from *

[DEMO - See how Pull Request warnings/errors are rendered in action](https://github.com/staabm/gh-annotation-example/pull/1/files)

Installation
============

[](#installation)

Install the binary via composer

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

💌 Give back some love
---------------------

[](#-give-back-some-love)

[Consider supporting the project](https://github.com/sponsors/staabm), so we can make this tool even better even faster for everyone.

Example Usage
=============

[](#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 GitHub Action workflow:

Process a checkstyle formatted file
-----------------------------------

[](#process-a-checkstyle-formatted-file)

```
cs2pr /path/to/checkstyle-report.xml
```

### Available Options

[](#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
- `--notices-as-warnings` Converts notices to warnings. This can be useful because GitHub does not annotate notices.
- `--prepend-filename` Prepend the filename to the output message
- `--prepend-source` When the checkstyle generating tool provides a `source` attribute, prepend the source to the output message.

Pipe the output of another commmand
-----------------------------------

[](#pipe-the-output-of-another-commmand)

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

Examples can bee seen below:

### Using [PHPStan](https://github.com/phpstan/phpstan)

[](#using-phpstan)

```
phpstan analyse --error-format=checkstyle | cs2pr
```

*Phpstan 0.12.32 introduced native github actions support, therefore you might use this instead:*

```
phpstan analyse
```

### Using [Psalm](https://github.com/vimeo/psalm)

[](#using-psalm)

```
psalm --output-format=checkstyle | cs2pr
```

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

```
psalm --output-format=github
```

### Using [PHP Coding Standards Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer)

[](#using-php-coding-standards-fixer)

```
php-cs-fixer fix --dry-run --format=checkstyle | cs2pr
```

### Using [PHP\_CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer)

[](#using-php_codesniffer)

```
phpcs --report=checkstyle -q /path/to/code | cs2pr
```

Note: the `-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
        id: phpcs
        run: phpcs --report-full --report-checkstyle=./phpcs-report.xml

      - name: Show PHPCS results in PR
        if: ${{ always() && steps.phpcs.outcome == 'failure' }}
        run: cs2pr ./phpcs-report.xml
```

### Using [PHP Parallel Lint](https://github.com/php-parallel-lint/PHP-Parallel-Lint/)

[](#using-php-parallel-lint)

```
vendor/bin/parallel-lint . --exclude vendor --checkstyle | cs2pr
```

### Using [Laravel Pint](https://github.com/laravel/pint)

[](#using-laravel-pint)

```
- name: Show Pint results in PR
run: pint --test --format=checkstyle | cs2pr
```

Note: if you want to have both logs and annotations you need to run `pint` twice:

```
- name: Check PHP code style
id: cs-check
run: pint --test

- name: Generate Annotations on CS errors
if: failure() && steps.cs-check.outcome != 'success'
run: pint --test --format=checkstyle | cs2pr
```

phpunit support?
----------------

[](#phpunit-support)

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

you might instead try

- a [phpunit problem matcher](https://github.com/shivammathur/setup-php#problem-matchers)
- a [phpunit-github-actions-printer](https://github.com/mheap/phpunit-github-actions-printer)

Example GithubAction workflow
-----------------------------

[](#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
```

Using cs2pr as a GitHub Action
------------------------------

[](#using-cs2pr-as-a-github-action)

You can also use [`cs2pr` itself as a GitHub Action](https://github.com/staabm/annotate-pull-request-from-checkstyle-action). This is useful if you want to for instance use it for a project that does not use PHP or if you want to use it with a custom PHP installation.

See the example at the [cs2pr GitHub Action repository](https://github.com/staabm/annotate-pull-request-from-checkstyle-action#readme).

Resources
=========

[](#resources)

[GithubAction Problem Matchers](https://github.com/actions/toolkit/blob/master/docs/problem-matchers.md)

Idea
====

[](#idea)

This script is based on a suggestion of [Benjamin Eberlei](https://twitter.com/beberlei/status/1218970454557372416)

The Code is inspired by

###  Health Score

64

—

FairBetter than 99% of packages

Maintenance76

Regular maintenance activity

Popularity60

Solid adoption and visibility

Community41

Growing community involvement

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 75.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~93 days

Recently: every ~338 days

Total

23

Last Release

244d ago

PHP version history (3 changes)1.0-beta1PHP ^7.0

1.3.0PHP ^7.0 || ^8.0

1.5.0PHP ^5.3 || ^7.0 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/99d4e5e5fa8fb7d0782de39b43c558953d0a5881a7ba596b90ed9c312db8c4d9?d=identicon)[staabm](/maintainers/staabm)

---

Top Contributors

[![staabm](https://avatars.githubusercontent.com/u/120441?v=4)](https://github.com/staabm "staabm (107 commits)")[![localheinz](https://avatars.githubusercontent.com/u/605483?v=4)](https://github.com/localheinz "localheinz (10 commits)")[![jrfnl](https://avatars.githubusercontent.com/u/663378?v=4)](https://github.com/jrfnl "jrfnl (4 commits)")[![donatj](https://avatars.githubusercontent.com/u/133747?v=4)](https://github.com/donatj "donatj (4 commits)")[![tristanbes](https://avatars.githubusercontent.com/u/346010?v=4)](https://github.com/tristanbes "tristanbes (2 commits)")[![HypeMC](https://avatars.githubusercontent.com/u/2445045?v=4)](https://github.com/HypeMC "HypeMC (1 commits)")[![Jampire](https://avatars.githubusercontent.com/u/686954?v=4)](https://github.com/Jampire "Jampire (1 commits)")[![kevinpapst](https://avatars.githubusercontent.com/u/533162?v=4)](https://github.com/kevinpapst "kevinpapst (1 commits)")[![AllenJB](https://avatars.githubusercontent.com/u/5645829?v=4)](https://github.com/AllenJB "AllenJB (1 commits)")[![korelstar](https://avatars.githubusercontent.com/u/6277619?v=4)](https://github.com/korelstar "korelstar (1 commits)")[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (1 commits)")[![prisis](https://avatars.githubusercontent.com/u/2716058?v=4)](https://github.com/prisis "prisis (1 commits)")[![rodrigoprimo](https://avatars.githubusercontent.com/u/77215?v=4)](https://github.com/rodrigoprimo "rodrigoprimo (1 commits)")[![sasezaki](https://avatars.githubusercontent.com/u/42755?v=4)](https://github.com/sasezaki "sasezaki (1 commits)")[![shivammathur](https://avatars.githubusercontent.com/u/1571086?v=4)](https://github.com/shivammathur "shivammathur (1 commits)")[![kojiromike](https://avatars.githubusercontent.com/u/1566303?v=4)](https://github.com/kojiromike "kojiromike (1 commits)")[![clxmstaab](https://avatars.githubusercontent.com/u/47448731?v=4)](https://github.com/clxmstaab "clxmstaab (1 commits)")[![edhgoose](https://avatars.githubusercontent.com/u/1108173?v=4)](https://github.com/edhgoose "edhgoose (1 commits)")[![glensc](https://avatars.githubusercontent.com/u/199095?v=4)](https://github.com/glensc "glensc (1 commits)")[![greg0ire](https://avatars.githubusercontent.com/u/657779?v=4)](https://github.com/greg0ire "greg0ire (1 commits)")

---

Tags

annotationscheckstylecheckstyle-xml-reportcs2prgithubactiongithubaction-workflowhacktoberfestphp-cs-fixerphpcsphpstanphpunitpipepsalmdevcontinous integrationGithub Actions

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/staabm-annotate-pull-request-from-checkstyle/health.svg)

```
[![Health](https://phpackages.com/badges/staabm-annotate-pull-request-from-checkstyle/health.svg)](https://phpackages.com/packages/staabm-annotate-pull-request-from-checkstyle)
```

###  Alternatives

[phpstan/phpstan

PHPStan - PHP Static Analysis Tool

13.9k341.8M29.6k](/packages/phpstan-phpstan)[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[phpmd/phpmd

PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD.

2.4k108.5M4.8k](/packages/phpmd-phpmd)[slevomat/coding-standard

Slevomat Coding Standard for PHP\_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.

1.5k123.5M1.8k](/packages/slevomat-coding-standard)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[pdepend/pdepend

Official version of pdepend to be handled with Composer

954110.9M815](/packages/pdepend-pdepend)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
