Add github logger to be able to use Annotations on GitHub Actions#1368
Add github logger to be able to use Annotations on GitHub Actions#1368maks-rafalko merged 21 commits intoinfection:masterfrom
Conversation
|
Just a quick note that there’s hardly any reason why Infection can’t output GitHub compatible annotations straight away. |
|
I mean we can skip this XML and cs2pr altogether by outputting the annotations right from Infection. This will also solve the problem I’ll mention in the review comments in a moment. |
infection.json.dist
Outdated
There was a problem hiding this comment.
Just like it so it could be:
"github": "/dev/stdout" // or /dev/stderr, whichever works bestAnd the it could output the annotations directly:
https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message
There was a problem hiding this comment.
If you look in the source of cs2pr, these annotations are pretty damn simple:
It is not to say we should scrap this new checkstyle report, but it won't exactly work here.
There was a problem hiding this comment.
I think it can be even better with "github" progress reporter.
There was a problem hiding this comment.
I think it can be even better with "github" progress reporter.
what is it?
There was a problem hiding this comment.
Like ProgressFormatter or DotFormatter. Set with --formatter option.
|
If I understood correctly, PHPStan enables this reporter automatically (?) on GitHub CI. Their implementation: https://github.com/phpstan/phpstan-src/blob/c99b7f8c09fe6e319624ef3b0b66f43d30056fe4/src/Command/ErrorFormatter/GithubErrorFormatter.php |
seems so, but I'm not sure it's a good choice TBH for Infection. Without proper filtering (as we do it right now), this will overload the diff with thousands of warnings by default (which MT can produce with even not very big projects) |
If Infection can detect it is running on GitHub (provided it was asked to do that), then it can fetch and run against changed files just as well. |
|
For example, specifying I agree it's not the best idea to enable this behavior by default. |
my opinion:
So, the current state of PR IMO is ideal - we give a developer new logger that can display GH Annotations to a file / What I think we should add (but in a separate PR), is an ability to set logger by command line option, like Why? To be able to not use checkstyle report for all the Infection runs in all currently available GH Actions, but to specify it only for |
That's what I was thinking when I proposed |
Infection is already very opinionated in a similar way. For example, by choosing to add a whitelist (or what's it called now) to Imagine you're writing a blog post. What would be better to write, that Infection will now automatically mutate only changed files if run with (I'd take it if you say that Infection shouldn't add |
I'm ok with a couple of lines to be added to CI config. This tool is for developers |
If there's |
|
Sounds good. I will give it a try, thanks! |
464def3 to
9d38e0f
Compare
…to `github` Automatically mutate only changed/added files when `--logger-github` is used
… to `--logger-github`
…ix escaped mutant
9b066a3 to
fb507b0
Compare
|
Thank you all for the great review and ideas! |
|
There's a Symfony's special reporting component now: |
| { | ||
| return (string) shell_exec( | ||
| sprintf( | ||
| 'git diff %s --diff-filter=%s --name-only | grep src/ | paste -sd ","', |
There was a problem hiding this comment.
Hardcoded src/ is likely to be wrong, it should be picked by config.
PR coming soon
## Context The user may apply a git filter in two different ways: - `--git-diff-filter=AD` - `--git-diff-lines` which is an alias for `--git-diff-filter=AM`. Now the issue is that since this is two distinct options, we need to distinguish the two inputs and validate them accordingly as they are mutually exclusive. I think there was some confusions before. The code evolved a lot since the filters were first introduced (#1368, #1632, #2394, #2542). Checking that the right options are passed correctly is now clearly enforced in `RunCommand` (see #2542) and `ConfigurationFactory` responsibility is to pass that `$sourceFilesFilter: string` value and the git related values when a git filter is applied. ## Problem Right now `Configuration#isForGitDiff` is set only if the user passed `--git-diff-lines`. This is incorrect as the goal of this value is to convey that we are applying a git diff of sorts for: - `IndexXmlCoverageParser` to throw a more understandable exception to the user when no coverage is found. - `FileMutationGenerator/NodeMutationGenerator` to only mutate the nodes that are part of the diff. In other words, it should not matter which option was used. ## Solution This PR corrects the value.
This PR:
--git-diff-filter,--git-diff-base,--logger-githubtions site#183Fixes #1322
Description
This feature allows adding errors/warnings for particular commits/PRs - GitHub Annotations
Basically, this feature adds escaped mutants information (diff) to particular lines where modified source code wasn't detected by tests:
Things to note
<details>tag to be able to show/hide huge text.Goal
This will greatly improve review process as it will be immediately clear what parts of the code are not covered by tests properly (thus escaped mutants)
Suggestions are appreciated.