-
Notifications
You must be signed in to change notification settings - Fork 472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for SARIF output format #2182
Conversation
@ondrejmirtes In your #765 review, you mentioned using I've tried to implement it but I have the following error:
|
Maybe you can use https://github.com/phpstan/phpstan-src/blob/1.9.11/src/Internal/ComposerHelper.php#L69 now? This has been simplified a bit in the meantime I believe |
Awesome! Thanks a lot @herndlm, it works like a charm. 👍 |
Hi, since this is expected to be consumed by an existing tool, it'd be great if you first tried your code on your own project (anyone can implement custom error formatters, they don't have to be in the core), tried it out on some error output, see if GitHub interprets it correctly, posted some screenshots, and then we'd be able to review this and merge it :) Thanks. |
@ondrejmirtes Yes, that was exactly my plan (and the reason it's still marked as draft). That being said I've 2 questions:
Thanks! |
Regarding the testing in another project: you can pull the phar from the compile action where it normally ends up as artifact. E.g. https://github.com/phpstan/phpstan-src/actions/runs/3923649573 |
That's what I was trying to say - you don't need to do anything crazy, just use last stable PHPStan ans implement the formatter in your own project. |
Tests on Windows are currently failing (malformed JSON) but I don't really know why, I'll investigate later. Other question: Thanks. |
I've created a repository to test the SarifErrorFormatter: https://github.com/jbelien/phpstan-sarif-test Here is the result (using GitHub Actions): |
As you can see "Rule ID" is defined as "[unknown-rule]". Is there a way to get the class name of the rule that triggered an error ? |
|
SARIF format allow you to upload those warnings and alerts to code GitHub Code Scanning report: More information about GitHub Code Scanning: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors The PHPStan report in SARIF format can be uploaded using https://docs.github.com/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github
The "security report" is indeed only available to contributors and not public (for obvious reason). |
No worries, I'll update SARIF formatter when/if that feature is implemented. 👍 |
What's the difference/benefit seeing the results in the "Security" tab versus status checks? Also, what's making me a bit sceptical about this is that most errors reported by PHPStan is not of security nature, so it might not be a great fit for this feature. |
In the end the result is indeed the same for a single repository.
Fully agree with you! The reason I started working on this is that I would like to have 100% of my repositories covered by code scanning in the coverage report (see screenshot above). |
This pull request has been marked as ready for review. |
Any update ? Thanks already. |
I've released I still think SARIF is a good a fit for an "official" formatter since SARIF stands for Static Analysis Results Interchange Format and is now a standard for static analysis report. In case you decide to integrate SARIF formatter in PHPStan itself, I'll archive my repository and keep the maintenance directly here ; otherwise, I'll just keep maintaining |
It still seems a bit weird to me. You're running PHPStan as part of your CI pipeline. The general expectation is that it has to be green, either by solving all errors, or by ignoring the remaining ones. Which means that the output formatter has nothing to output. But in #2182 (comment) it looks like you want this formatter to achieve some kind of dashboard of PHPStan errors across projects in your organization. Which means that your projects would have red CI pipelines... |
Yes, that's exactly what I'm trying to achieve here. My comment was just an example of the use of SARIF in GitHub.
Maybe my explanations were not clear but that's of course not what I'm trying to get. |
When your pipeline is green, you're not gonna see anything in the Code scanning section. When your pipeline is red, you already have a nice output right inside the workflow that's running PHPStan. Thanks to automatically detected CI and the I don't really see any place for SARIF format in this usual workflow. |
No worries then, I'll just use the SARIF formatter separately then. 👍 I still think it would make sense to include it in PHPStan itself but the only thing that really matters is that it's working. 😄 |
📢 For people looking for the SARIF formatter, here it is: https://github.com/jbelien/phpstan-sarif-formatter |
This PR adds a new output format: Static Analysis Results Interchange Format (SARIF) Version 2.1.0.
This format is for instance used by GitHub Code Scanning features ; implementing this should allow us to "export" all alerts reported by PHPStan in Code Scanning alerts using GitHub Actions.
This is still a work in progress, I'll add the missing tests (based on the test made for
JsonErrorFormatter
) but I'm already looking forward for input.