Add GitHub annotations formatting option#64
Add GitHub annotations formatting option#64reiniscirpons wants to merge 4 commits intojames-d-mitchell:mainfrom
Conversation
|
@fingolfin could you check if this does what you want and displays the annotations correctly in the github CI? Running it with Sample output of the first few warnings when running Sample output of the first few warnings when running |
|
This looks good, thank you! But ultimately it should be tested under "real" conditions: I.e. set up a git repository with a GH workflow which invokes (And then perhaps someone can turn this into a prepackeged action, say |
Started doing so in a fork of the example gap package project, see PR here reiniscirpons/gap-gaplint-github-annotation-test#1 . It seems that no annotations are being generated for the newly added file, but curiously it does produce some (but not all) annotations for the existing It seems https://github.com/actions/runner/blob/main/src/Runner.Worker/ActionCommandManager.cs#L608 is the code in the GH actions runner that is responsible for creating the annotations. |
|
Update: after trawling the web it seems that there is a limit of 10 annotations that get generated (see https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md#limitations), this is not 10 annotation per file, its 10 annotations total. There is also no indication that there are more annotations that were not displayed. So it seems like, if this were to be used in CI workflows, its crucial to a) only run gaplint on modified or newly added files and not already existing files (as these eat up the limit too) and b) communicate that more warnings could be present to the end user to prevent frustrating whack-a-mole situations where developers end up fixing 10 lints at a time only to see more crop up every time they push. |
|
Yeah it would important to either limit the annotations to ranges of code that were actually touched by the current commit; or to advise people to only use the action after they formatted their entire code base (but of course that's a somewhat limiting restriction, some projects may wish to migrate gradually shrug) As to the limit of 10 annotations, I wasn't aware but that explains some bad experience I had in the past (where I indeed thought I'd fixed all and then I got more...) But I'd try to address this as follows:
|
This PR adds functionality requested in #63 . In particular it adds a
--github-annotationsflag, which, when toggled formats the output ofgaplintto match the format expected by GitHub CI runners to display code annotations, see also https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands#setting-an-error-message .To do so, I refactored the existing diagnostic printing logic by writing a separate
DiagnosticFormatterclass, which allows us to easily create new formatters conforming to a custom format in a few lines of configuration code. For example, below is the default and github formatter specification:I also added an additional field to the
Diagnosticclass calleddiagnostic_typewhich stores information on whether the diagnostic is a warning or error (this is set by the calling_warnor_errorfunctions respectively). This allows the github annotation to more accurately reflect the type of diagnostic encountered.Finally, more tests were added to test the actual textual representation of diagnostics (this was previously not done) and the expected output pickling script was updated to work with the changes introduced in #59 . Expected output was repickled so that diagnostics would also store the newly added
diagnostic_typefield.