This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Robin Chalas 04eec8bfc7 feature #38982 [Console][Yaml] Linter: add Github annotations format for errors (ogizanagi)
This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[Console][Yaml] Linter: add Github annotations format for errors

| Q             | A
| ------------- | ---
| Branch?       | 5.x <!-- see below -->
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | N/A <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | TODO

Github actions [can write errors and warning](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-error-message) directly in their output, which result into annotations into the Github checks. It can even provide a filename, line & col number, allowing to display the annnotations inside the PR diff directly, at the right place.

More advanced usage of annotations can be made using the [API](https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-run-annotations), but regarding the linters provided in Symfony components, it seems the shortcut using output is a great way to enhance the integration with Github Actions.

This PR starts by proposing these changes in the yaml linter:
- add the `github` format, which is the same as the `txt` one, except for errors and warning, for which we'll adapt the output to the Github annotations format.
- remove the `txt` format as default, and autodetect if the script is running in a Github action context, then use `github` format. If it's not, we fallback to `txt` as before.

Once we agree on the details, we could perform the same for other linters (xliff, twig, ...)

Here is a PR using it: https://github.com/ogizanagi/symfony-lint-gha-demo/pull/2

and some screenshots:

| PR checks run | PR checks annotations | PR diff |
| -- | -- | -- |
| ![Capture d’écran 2020-11-04 à 09 37 07](https://user-images.githubusercontent.com/2211145/98089377-ed416600-1e82-11eb-8b10-40602b45efb1.png) | ![Capture d’écran 2020-11-04 à 09 37 28](https://user-images.githubusercontent.com/2211145/98089379-edd9fc80-1e82-11eb-8302-4e104abaeb2c.png) | ![Capture d’écran 2020-11-04 à 09 38 28](https://user-images.githubusercontent.com/2211145/98089381-edd9fc80-1e82-11eb-982a-9e4413ec30ba.png) |

~~(tests to add)~~

---

This was inspired by [PHPStan](d77bd87da9/src/Command/ErrorFormatter/GithubErrorFormatter.php) which is already auto-adapting the output according to the CI, using https://github.com/OndraM/ci-detector

Commits
-------

f0bbdc8d72 [Console][Yaml] Linter: add Github annotations format for errors
2020-11-20 09:48:18 +01:00
.github Merge branch '5.1' into 5.2 2020-11-18 10:58:20 +01:00
src/Symfony feature #38982 [Console][Yaml] Linter: add Github annotations format for errors (ogizanagi) 2020-11-20 09:48:18 +01:00
.appveyor.yml Merge branch '4.4' into 5.1 2020-11-02 16:45:32 +01:00
.editorconfig Update .editorconfig 2018-09-06 16:22:56 +02:00
.gitignore Run the phpunit-bridge from a PR 2019-08-02 17:46:19 +02:00
.php_cs.dist Merge branch '5.1' into 5.x 2020-10-28 22:46:03 +01:00
.travis.yml Merge branch '4.4' into 5.1 2020-11-16 16:58:32 +01:00
CHANGELOG-5.0.md Merge branch '5.0' into 5.1 2020-06-15 13:50:15 +02:00
CHANGELOG-5.1.md Update CHANGELOG for 5.1.8 2020-10-28 06:55:13 +01:00
CHANGELOG-5.2.md Update CHANGELOG for 5.2.0-RC1 2020-11-10 08:54:29 +01:00
CODE_OF_CONDUCT.md Added the Code of Conduct file 2018-10-10 03:13:30 -07:00
composer.json [Messenger][SQS] Make sure one can enable debug logs 2020-11-11 14:16:39 +01:00
CONTRIBUTING.md Mention the community review guide 2016-12-18 22:02:35 +01:00
CONTRIBUTORS.md Update CONTRIBUTORS for 3.4.46 2020-10-28 06:38:46 +01:00
LICENSE Update year in license files 2020-01-01 12:03:25 +01:00
link Improve link script with rollback when using symlink 2020-08-21 19:05:22 +02:00
phpunit Simplify phpunit script. 2020-10-28 21:38:43 +01:00
phpunit.xml.dist Merge branch '4.4' into 5.1 2020-11-16 16:58:32 +01:00
README.md Minor improvement 2020-07-29 07:57:47 +02:00
UPGRADE-5.0.md Typo: somes styles fixed 2020-08-06 09:00:23 +02:00
UPGRADE-5.1.md Update UPGRADE-5.1.md 2020-09-07 01:58:27 +02:00
UPGRADE-5.2.md [Validator] Allow load mappings from attributes without doctrine/annotations. 2020-11-07 22:48:53 +01:00
UPGRADE-6.0.md [Validator] Allow load mappings from attributes without doctrine/annotations. 2020-11-07 22:48:53 +01:00

Symfony is a PHP framework for web and console applications and a set of reusable PHP components. Symfony is used by thousands of web applications (including BlaBlaCar.com and Spotify.com) and most of the popular PHP projects (including Drupal and Magento).

Installation

Documentation

Community

Contributing

Symfony is an Open Source, community-driven project with thousands of contributors. Join them contributing code or contributing documentation.

Security Issues

If you discover a security vulnerability within Symfony, please follow our disclosure procedure.

About Us

Symfony development is sponsored by SensioLabs, led by the Symfony Core Team and supported by Symfony contributors.