mfridman / tparse

CLI tool for summarizing go test output. Pipe friendly. CI/CD friendly.
MIT License
948 stars 22 forks source link

Option `-follow` when using `-format markdown` (Github Actions) #77

Open embano1 opened 2 years ago

embano1 commented 2 years ago

-follow is a very useful option. However, when using it in conjunction with -format markdown and >> $GITHUB_STEP_SUMMARY to create nice job summaries, the output is of course not as expected.

Would it make sense to exclude the -follow output from the generated -format to avoid this issue?

mfridman commented 2 years ago

Maybe, need to think about this one..

I got around this by outputting to a JSON file and then parsing that. See the example here:

https://github.com/mfridman/tparse/blob/e2da1ad98541a56759a35afa743d5e0432041175/.github/workflows/ci.yml#L32-L39

Which maintains the followed output in the CI, but the summary ignores that.

https://github.com/mfridman/tparse/actions/runs/2613602194

embano1 commented 2 years ago

Yes, that was my workaround :) But pretty sure you're also not happy about this one :D

mfridman commented 2 years ago

Ye, not ideal.

Would it make sense to exclude the -follow output from the generated -format to avoid this issue?

I don't think that'll work, or maybe I'm missing something.

The test output is piped to tparse, it's internally parsed and written out to standard out immediately with -follow. Then that go non-json test output is appended to the Github summary file along with the tables at the end.

Given both -follow and >> I don't see how we can separate the output from ending up in .

One solution I thought was adding a flag -github-summary flag and instead of you adding a >> $GITHUB_STEP_SUMMARY .. tparse would write out to that file instead.

embano1 commented 1 year ago

IMHO what could work is that tparse would ignore "Action":"output" when sending the buffer to $GITHUB_STEP_SUMMARY?

mfridman commented 1 year ago

What if instead of writing out to >> $GITHUB_STEP_SUMMARY, there was instead an -output flag.

go test ... | tparse ... -format=markdown -output=$GITHUB_STEP_SUMMARY

This option points to a file, such as $GITHUB_STEP_SUMMARY, and writes the markdown content (excluding output) to that file.

I could see this being useful outside of just github summary steps.

embano1 commented 1 year ago

So $GITHUB_STEP_SUMMARY would be a magic file name then or is this already an env in Github CI which resolves to a particular file name? (haven't looked deeper into that var)

mfridman commented 1 year ago

Yep, $GITHUB_STEP_SUMMARY resolves to a path on the runner for each step in a job. The path is something like this:

/home/runner/work/_temp/_runner_file_commands/step_summary_093735d6-8c78-4a6c-b4af-e9a7298a5e60

I think this might work, will give this a go once I find some cycles.

ti-mo commented 1 year ago

Why not send test all "Action":"output" lines to tparse's stderr? That way, the user can expect colored/markdown output on stdout and test output on stderr.