Skip to content

Conversation

@fkj
Copy link
Contributor

@fkj fkj commented Mar 21, 2025

This adds a new CLI parameter, --output-format, which can be set to either default or github.
The default option preserves the current way to print analyzer results to stdout.

The github option instead prints the analyzer results in a format that can be understood as a code annotation by GitHub Actions (reference).
This feature allows users without a GitHub Advanced Security subscription to get nicely formatted analyzer results in CI for private repositories.

Here are some (lightly censored) screenshots of what it looks like in a real code base.

In the "Files changed" section of a pull request:
Screenshot 2025-03-21 at 12 35 52

In the workflow log view:
Screenshot 2025-03-21 at 12 37 04

The main limitation of this is that GitHub has a hard limit of 10 annotations per PR. But for organizations that keep their number of warnings low, most PRs should not introduce more than 10 new analyzer warnings.
Also, GitHub annotations only have three severity levels, so I've mapped both Hint and Info into the ::notice level.

Closes #229.

This will be used to select other output formats on stdout.
If nothing is selected, the default output format is chosen.
If the parameter value is not understood, an error is printed, but the
default output format is still chosen.
Copy link
Member

@TheAngryByrd TheAngryByrd left a comment

Choose a reason for hiding this comment

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

Looks good overall :)

The main limitation of this is that GitHub has a hard limit of 10 annotations per PR. But for organizations that keep their number of warnings low, most PRs should not introduce more than 10 new analyzer warnings.

What happens when you go over 10? Does it just stop presenting warnings? This might also be worth mentioning in the Running during CI.md file.

|> ignore
)

let msgLogger = factory.CreateLogger("")
Copy link
Member

Choose a reason for hiding this comment

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

Worth commenting we don't want to specify a name since it would interfere with the output that github is expecting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 8348afd.

@fkj
Copy link
Contributor Author

fkj commented Mar 21, 2025

What happens when you go over 10? Does it just stop presenting warnings? This might also be worth mentioning in the Running during CI.md file.

I have added some explanation in 3d31e00. The limit is actually 10 per annotation type. The log will always contain all analyzer results, but only the first 10 annotations of each type will appear in the rest of the GitHub UI.

Copy link
Member

@TheAngryByrd TheAngryByrd left a comment

Choose a reason for hiding this comment

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

Approving, but I'll give others time to review too.

Thanks for this!

This output format prints results in a format that is understood as code
annotations by GitHub Actions.
This can be used as a replacement for SARIF files for users who don't
have access to GitHub Advanced Security.
@fkj fkj force-pushed the add-github-logging-output-format branch from 3d31e00 to 1e0d381 Compare March 25, 2025 08:57
@fkj
Copy link
Contributor Author

fkj commented Mar 25, 2025

Force-pushed to auto-squash fixup commits.

@TheAngryByrd TheAngryByrd merged commit bc778c3 into ionide:main Mar 26, 2025
2 checks passed
@fkj fkj deleted the add-github-logging-output-format branch March 26, 2025 08:11
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.

Add ability to log results in Github Workflow Command format

2 participants