toolkit icon indicating copy to clipboard operation
toolkit copied to clipboard

Multiline support for Toolkit Annotations

Open svartalf opened this issue 6 years ago • 15 comments
trafficstars

This is a follow-up issue started at https://github.com/actions/toolkit/issues/186#issuecomment-546772099.

It is unclear from the recently added Annotation docs if ::debug/::warning/::error messages support multiline text in the {message} placeholder.

Why it is important? These Annotations can be used by various code linters and other similar tools, but their output easily could be spanned to multiple lines, for example:

pylint output:

W:108: Operator not followed by a space
     print >>sys.stderr, 'Unable to match %r', line
            ^

Rust compiler output:

warning: comparison is useless due to type limits
  --> example/src/lib.rs:20:8
   |
20 |     if pid < 0 {
   |        ^^^^^^^
   |
   = note: `#[warn(unused_comparisons)]` on by default

It would be nice to clarify if it is possible to use multiline strings over there and it is expected to be working correctly in the future.

svartalf avatar Oct 28 '19 09:10 svartalf

+1 At least some kind of initial feedback. Is it possible or not? And then maybe follow up with updating the docs.

danechitoaie avatar Nov 14 '19 19:11 danechitoaie

+1. This is one of the last blocking issues blocking me from moving to Github Actions. The output of my test suites failures are much longer than a single line, and I have no way to display them nicely.

EricWF avatar Mar 28 '20 02:03 EricWF

It can be achieved by using urlencoded newline %0A in place of \n.

I learned it from a comment by @PoisonousJohn at https://github.com/actions/starter-workflows/issues/68#issuecomment-581479448

I've confirmed it working for PHPUnit output and have a PR: https://github.com/mheap/phpunit-github-actions-printer/pull/14/files

And here's a screenshot of the outcome: https://i.imgur.com/nnSCPTG.png

Zero documentation anywhere, thank you @PoisonousJohn !

BrianHenryIE avatar Mar 28 '20 04:03 BrianHenryIE

I just discovered this, Cheers! I can confirm it works and have used it successfully in a workflow.

PS. @BrianHenryIE Have you discovered a way to make problem matchers work with multi-line messages?

EricWF avatar Mar 28 '20 05:03 EricWF

Wow, such an important feature and the only way to solve it is via an undocumented hack.

Why not just use a json object printed on one line, which can be readily produced with e.g. jq? Is this the quality standard the Github Actions team wants to stay at?

Profpatsch avatar Jun 21 '22 13:06 Profpatsch

The same trick can be used in echo "::warning::multi%0Aline" commands within a workflow. This creates a multiline annotation, but only the first line in the build log is going to be highlighted, all that follows show up as normal.

Fleshgrinder avatar Sep 29 '22 13:09 Fleshgrinder

The same trick can be used in echo "::warning::multi%0Aline" commands within a workflow.

Unfortunately, this trick doesn't work anymore: image

rhaschke avatar Aug 24 '23 05:08 rhaschke

The Command class (still) uses this escaping: https://github.com/actions/toolkit/blob/7b617c260dff86f8d044d5ab0425444b29fa0d18/packages/core/src/command.ts#L80-L85

rhaschke avatar Aug 24 '23 06:08 rhaschke

@rhaschke It seems the %0A trick still works, see https://github.com/pgf-tikz/pgf/actions/runs/7294270657.

muzimuzhi avatar Dec 22 '23 00:12 muzimuzhi

It seems the %0A trick still works, see https://github.com/pgf-tikz/pgf/actions/runs/7294270657.

For me, the multi-line output is only shown correctly when clicking "show more". Without that expansion, everything shows up in a single line, doesn't it? In my example (with a shorter line) it doesn't work: https://github.com/rhaschke/test/actions/runs/5961263674 As the line(s) are too short, there is no "show more" button provided.

rhaschke avatar Dec 22 '23 00:12 rhaschke

@rhaschke Yes, you observation is right.

muzimuzhi avatar Dec 22 '23 01:12 muzimuzhi

The new lines (escaped with %0A) don't appear to be respected in the annotation view of the errors...

new lines are not displayed

Screenshot 2024-03-05 at 9 09 07 AM

raw logs show newlines correctly

Screenshot 2024-03-05 at 9 09 26 AM

Also, I definitely expected it to respect markdown but it does not, which is surprising.

justinmchase avatar Mar 05 '24 15:03 justinmchase

Is there any actual way that works here? %0A does not work for me as well now.

tsigouris007 avatar Apr 04 '24 09:04 tsigouris007

I search for something similar but unable to find. I'd like to display valgrind's logs for memory leaks as an Error annotation, but it's multiline. I tried to do so :

-   name: "Analyze valgrind report"
    run: |
        status=0
        block=""
        while IFS= read -r line; do
            if [[ "${block}" != "" ]]; then
                if [[ $(echo "${line}" | grep '^==.*== $') ]]; then
                    echo "::error title=\"Valgrind Error\"::${block}"
                    block=""
                    status=1
                else
                    block="${block}
        ${line}"
                fi
            fi
            if [[ $(echo "${line}" | grep '^==.*== .* bytes in .* blocks are definitely lost in loss record .* of .*$') ]]; then
                block="${line}"
            fi
        done < valgrind-reports.log
        rm -f valgrind-reports.log
        exit "${status}"

And you can see that I'm leaving a line, without having to specify %0A, but the result is quite similar to the one above.

image image

I think it would be cool to have a sort of ::group:: ::endgroup:: but making it working for error, warning and so on, so it also gets displayed on the workflow summary.

In fact, it appeared that %0A works, I mean, at least regarding the summary : image

But when clicking on the details, other logs are still shown outside of the error scope.

Ximaz avatar Apr 28 '24 11:04 Ximaz