junit-plugin icon indicating copy to clipboard operation
junit-plugin copied to clipboard

Github Checks annotation

Open wilrnh opened this issue 4 years ago • 10 comments

Dependencies

checks-api

Feature Request

The checks-api plugin which this junit plugin uses supports annotating files with line numbers and other goodies. Would it be possible to add this. I couldn't find any issues or prs where this might have been explored before which is kinda surprising. Can anyone think of any reason junit should not be annotating checks?

http://www.jenkins.io/doc/pipeline/steps/checks-api/#publishchecks-publish-customized-checks-to-scm-platforms

wilrnh avatar Aug 26 '21 20:08 wilrnh

The junit plugin would need to parse error messages and stack traces for filenames and line numbers. How to do this is not always obvious. In the case of Java,

    at x.y.z.C$Inner.someMethod(C.java:123)

means you need to look for a file in the repository x/y/z/C.java typically in some subdirectory like module/src/main/java/ and annotate line 123 (which may or may not even have been edited in the annotated PR).

jglick avatar Aug 26 '21 21:08 jglick

thx for checking this out @jglick

my junit.xmls have s with file and line number attrs. maybe we can just use those when available?

wilrnh avatar Aug 27 '21 02:08 wilrnh

Maybe. The file format is poorly standardized and each test harness will have its own conventions for how filenames are reported, so the plugin would need to use some heurstics.

jglick avatar Aug 27 '21 14:08 jglick

The file format is poorly standardized and each test harness will have its own conventions

trust me i know :disappointed:

the plugin would need to use some heurstics

maybe start with something simple like if file exists in the workspace, annotate it? (just throwing stuff out, this could be a terrible idea...)

wilrnh avatar Aug 27 '21 14:08 wilrnh

There’s no guarantee the test file will have been changed in the PR though right? Is there a value in annotating one that hasn’t changed?

timja avatar Aug 27 '21 15:08 timja

Is there a value in annotating one that hasn’t changed?

Generally not, but currently GitHub will display the annotation regardless and you cannot turn this off except by pressing (IIRC) A when viewing the Files tab. (The analogous CloudBees CI integration with Checks explicitly suppresses line annotations which are not present in the PR’s diff hunks.)

jglick avatar Aug 27 '21 16:08 jglick

the test file

Note that a stack trace (or whatever you have, depending on language & framework) may refer to multiple lines in multiple files, both production sources and tests., any (or none) of which might be the “culprit” of a failure.

jglick avatar Aug 27 '21 16:08 jglick

Generally not, but currently GitHub will display the annotation regardless and you cannot turn this off

this seems like a dealbreaker, and not worth the confusion for something atm that is just eye-candy.

but what if we gave the end user an option to annotate at their own risk via a junit step param?

wilrnh avatar Aug 30 '21 13:08 wilrnh

something atm that is just eye-candy

Well, this could be really useful. If in a PR you write a test which fails in CI, or if some code you edit in a PR throws an exception during some existing tests, having that be called out right in the Files tab at the point of the mistake would be a lot nicer than having to go through a list of test failures in the Checks tab and manually correlate stack traces to lines of code in your IDE.

jglick avatar Aug 30 '21 19:08 jglick

very def, this is what i was thinking. sry didnt mean to make it sound completely useless

wilrnh avatar Aug 31 '21 13:08 wilrnh