Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
embano1 opened this issue Jul 7, 2022 · 8 comments
Open

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

embano1 opened this issue Jul 7, 2022 · 8 comments

Comments

@embano1
Copy link

embano1 commented Jul 7, 2022

-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
Copy link
Owner

mfridman commented Jul 7, 2022

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:

- name: Run tests with GITHUB_STEP_SUMMARY
# Note the use of || true. This so the job doesn't fail at that line. We want to preserve -follow
# as part of the test output, but not output it to the summary page, which is done in the proceeding
# command when we parse the output.json file.
run: |
go test -count=1 -race ./... -json -coverpkg github.com/mfridman/tparse/parse \
| tee output.json | ./tparse -notests -follow -all || true
./tparse -format markdown -file output.json -all -slow 5 > $GITHUB_STEP_SUMMARY

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

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

@embano1
Copy link
Author

embano1 commented Jul 7, 2022

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

@mfridman
Copy link
Owner

mfridman commented Jul 8, 2022

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
Copy link
Author

embano1 commented Jul 9, 2022

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

@mfridman
Copy link
Owner

mfridman commented Jul 10, 2022

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
Copy link
Author

embano1 commented Jul 11, 2022

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
Copy link
Owner

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
Copy link

ti-mo commented May 26, 2023

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.

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

No branches or pull requests

3 participants