Skip to content

Introduce ErrorFormatter for GitHub Actions#261

Merged
ondrejmirtes merged 4 commits intophpstan:masterfrom
Quetzacoalt91:github-formatter
Jun 30, 2020
Merged

Introduce ErrorFormatter for GitHub Actions#261
ondrejmirtes merged 4 commits intophpstan:masterfrom
Quetzacoalt91:github-formatter

Conversation

@Quetzacoalt91
Copy link
Copy Markdown
Contributor

This PR allows PHPStan to report errors on the GitHub interface when used with GitHub Actions, in pull-requests changes. We started using this formatter at PrestaShop to help our contributor to find the required changes easily (PrestaShop/php-dev-tools#24).

image

Note the only displayed errors are targeting a specific line of a file, generic errors (= Not file specific) are not concerned. For developers looking at the complete report in the log, the class TableErrorFormatter is used so they can read the default view.

Copy link
Copy Markdown
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Can you point me to some docs about the format GitHub Actions use?
  2. What happens about errors reported on files that haven't changed in a pull request?

Otherwise I like it! 👍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Composition over inheritance should be used. Ask for TableErrorFormatter in the constructor, do not extend from it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All should be errors.

@Quetzacoalt91
Copy link
Copy Markdown
Contributor Author

While I'm applying the changes, you can find more details about the annotations here: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message

@ondrejmirtes
Copy link
Copy Markdown
Member

Would be a good idea to link it in the implementation :)

@Quetzacoalt91
Copy link
Copy Markdown
Contributor Author

Quetzacoalt91 commented Jun 29, 2020

Changes have been applied. :) About your question:

What happens about errors reported on files that haven't changed in a pull request?

GitHub will display them anyway in a dedicated space, below the diff. Unfortunately I don't have any link to provide as an example (the PR was updated), only a screenshot I took while PHPStan was in action.

image

@ondrejmirtes
Copy link
Copy Markdown
Member

That’s really nice! Could we somehow incorporate notFileSpecificErrors too? How GitHub behaves when we add an error to a nonexistent file?

@Quetzacoalt91
Copy link
Copy Markdown
Contributor Author

We could add them in the report, but I didn't in the original version as finding them is not an intuitive task. These issues are reported in the action tab when we select the related workflow:

image

@staabm
Copy link
Copy Markdown
Contributor

staabm commented Jun 30, 2020

To achieve the same effect I usually use the checkstyle output format and https://github.com/staabm/annotate-pull-request-from-checkstyle

This works across different tools and is already bundled in the often used GithubAction shivammathur/setup-php tools

@ondrejmirtes
Copy link
Copy Markdown
Member

@Quetzacoalt91 I really like how it looks! Besides notFileSpecificErrors, we could also present warnings as actual warnings. You can create a warning for example by not escaping regex-special characters in ignoreErrors:

* Generates a warning: #Result of || is always false#
* Does not generate a warning: #Result of \|\| is always false#

@staabm I'm aware of this but built-in formatter creates new opportunities like do this by default if we detect we're running in GitHub Actions.

@Quetzacoalt91
Copy link
Copy Markdown
Contributor Author

All right, at the same time I added the warning you were talking about, I added the generic errors as GitHub handle them in a way.

@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you, I love it. Will merge it if the build passes. I'll also try to make it the default, but I want to tackle that myself.

@Quetzacoalt91
Copy link
Copy Markdown
Contributor Author

Thanks for your time with the improvements, I’m glad you like it. :)

@ondrejmirtes ondrejmirtes merged commit 123ffab into phpstan:master Jun 30, 2020
@ondrejmirtes
Copy link
Copy Markdown
Member

FYI 6e7d5f6 + 6fd85e3

@b1rdex
Copy link
Copy Markdown
Contributor

b1rdex commented Jul 1, 2020

Is the same or similar possible for Gitlab?

@ondrejmirtes
Copy link
Copy Markdown
Member

Doesn't look like so: https://twitter.com/johannpardanaud/status/1278273861088395264

There's already a gitlab error formatter but I think it's limited to the paid version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants