All Projects → staabm → annotate-pull-request-from-checkstyle

staabm / annotate-pull-request-from-checkstyle

Licence: MIT license
cs2pr - Annotate a GitHub Pull Request based on a Checkstyle XML-report within your GitHub Action

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to annotate-pull-request-from-checkstyle

CI-Report-Converter
The tool converts different error reporting standards for deep compatibility with popular CI systems (TeamCity, IntelliJ IDEA, GitHub Actions, etc).
Stars: ✭ 17 (-88.36%)
Mutual labels:  checkstyle, phpcs, phpstan, psalm
php-toolbox
🐳 A Docker image designed for PHP developers that care about code quality.
Stars: ✭ 18 (-87.67%)
Mutual labels:  phpunit, php-cs-fixer, phpstan, psalm
php-skeleton
A skeleton to start new high-quality PHP projects without worrying about bootstrapping everything from scratch.
Stars: ✭ 23 (-84.25%)
Mutual labels:  phpunit, phpcs, phpstan
noise-php
A starter-kit for your PHP project.
Stars: ✭ 52 (-64.38%)
Mutual labels:  phpunit, phpstan, psalm
slim-skeleton
Slim Framework skeleton application following MVC construction
Stars: ✭ 18 (-87.67%)
Mutual labels:  phpunit, phpcs
phpunit-injector
Injects services from a PSR-11 dependency injection container to PHPUnit test cases
Stars: ✭ 62 (-57.53%)
Mutual labels:  phpunit, annotations
atom-php-cs-fixer
Run the 'PHP Coding Standards Fixer' within Atom
Stars: ✭ 30 (-79.45%)
Mutual labels:  php-cs-fixer, phpcs
Github-Android-Action
Android Github Action that builds Android project, runs unit tests and generates debug APK, builds for Github Actions hackathon
Stars: ✭ 29 (-80.14%)
Mutual labels:  githubaction, githubaction-workflow
phpunit-extensions
📦 Some cool extensions for PHPUnit
Stars: ✭ 28 (-80.82%)
Mutual labels:  phpunit
phpstan-ga
GithubAction for PHPStan
Stars: ✭ 85 (-41.78%)
Mutual labels:  phpstan
files-io
Read many files with node
Stars: ✭ 19 (-86.99%)
Mutual labels:  pipe
annotation-cache-bundle
Annotation based caching for services inside a symfony container
Stars: ✭ 16 (-89.04%)
Mutual labels:  annotations
asynit
🌠 Asynchronous HTTP Request Testing Library for API or more...
Stars: ✭ 74 (-49.32%)
Mutual labels:  phpunit
windigo-android
Windigo is easy to use type-safe rest/http client for android
Stars: ✭ 23 (-84.25%)
Mutual labels:  annotations
Phexecute
Phexecute - Awesome PHP Code Runner
Stars: ✭ 18 (-87.67%)
Mutual labels:  phpunit
woocommerce-stubs
WooCommerce function and class declaration stubs for static analysis.
Stars: ✭ 49 (-66.44%)
Mutual labels:  phpstan
linkedresearch.org
🌐 linkedresearch.org
Stars: ✭ 32 (-78.08%)
Mutual labels:  annotations
Form-Labeller
Use this tool to label forms, bounding boxes, and assigning types to annotations
Stars: ✭ 17 (-88.36%)
Mutual labels:  annotations
tester-phpunit
tester runner for phpunit on atom editor
Stars: ✭ 34 (-76.71%)
Mutual labels:  phpunit
illuminsight
💡👀 Read EPUB books with built-in insights from wikis, definitions, translations, and Google.
Stars: ✭ 55 (-62.33%)
Mutual labels:  annotations

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

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

DEMO - See how Pull Request warnings/errors are rendered in action

Installation

Install the binary via composer

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

💌 Give back some love

Consider supporting the project, so we can make this tool even better even faster for everyone.

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

cs2pr /path/to/checkstyle-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
  • --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

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

Examples can bee seen below:

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

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

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

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].