staabm/annotate-pull-request-from-checkstyle
Composer 安装命令:
composer require --dev staabm/annotate-pull-request-from-checkstyle
包简介
README 文档
README
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.
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 --dev
💌 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-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 asourceattribute, 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 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
vendor/bin/parallel-lint . --exclude vendor --checkstyle | cs2pr
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 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
Using cs2pr as a GitHub Action
You can also use cs2pr itself as a GitHub 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.
Resources
Idea
This script is based on a suggestion of Benjamin Eberlei
The Code is inspired by https://github.com/mheap/phpunit-github-actions-printer
staabm/annotate-pull-request-from-checkstyle 适用场景与选型建议
staabm/annotate-pull-request-from-checkstyle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.77M 次下载、GitHub Stars 达 201, 最近一次更新时间为 2020 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「dev」 「continous integration」 「Github Actions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 staabm/annotate-pull-request-from-checkstyle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 staabm/annotate-pull-request-from-checkstyle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 staabm/annotate-pull-request-from-checkstyle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Monolog bridge for PHP Debugbar
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
Simple and fast methods to read private properties and call private methods
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
Analysis module for finding problematical shop data.
Analysis module for finding problematical shop data.
统计信息
- 总下载量: 3.77M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 201
- 点击次数: 19
- 依赖项目数: 114
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-22
