github-action-markdown-link-check icon indicating copy to clipboard operation
github-action-markdown-link-check copied to clipboard

Add failures as comments on PR

Open gaurav-nelson opened this issue 4 years ago • 12 comments

Similar to https://github.com/gaurav-nelson/github-action-vale-lint

gaurav-nelson avatar Oct 17 '19 00:10 gaurav-nelson

Probably not a good idea as sometimes there are a huge number of broken links.

gaurav-nelson avatar Apr 09 '20 01:04 gaurav-nelson

Can truncate your first X results.

On Thu, Apr 9, 2020 at 02:50, Gaurav Nelson [email protected] wrote:

Probably not a good idea as sometimes there are a huge number of broken links.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

philsturgeon avatar Apr 09 '20 09:04 philsturgeon

Thanks @philsturgeon I thought, no one needs this feature. I'm opening this back again.

gaurav-nelson avatar Apr 10 '20 00:04 gaurav-nelson

Idea: Store the output in a variable (output at the step). Then, the user can use another action to create an issue: https://github.com/JasonEtco/create-an-issue. (OK issue != PR, however links tend to break independently to a PR. Thus a weekly check could be a good idea).

koppor avatar May 28 '20 06:05 koppor

Agree if the output is a variable/file I could easily write an action that would pick that up and create a comment in the PR, maybe just with the first 10 items or something to not clutter the PR discussion.

The workflow I am thinking about is that while the check fails, going to the details of the action is not something the average markdown writer might be comfortable doing, in one of my projects we have many people who are brand new to markdown + github. Plus having the content in the PR discussion keeps the workflow in one place and they can easily see the content they need to fix.

Happy to collaborate on writing this issue if we can get that output.

Matticusau avatar Aug 10 '20 22:08 Matticusau

Hi there, thanks for this helpful and thorough action.

Was looking for a way to get the output of the link check and stumbled over this issue. Would support an option that exposes the output to another step like @koppor proposed. Thus, the decision where the output should finally be sent to (PR, issue, cache, artifacts, file, etc.) could be left open to the consumer of the action.

musicEnfanthen avatar Nov 14 '20 16:11 musicEnfanthen

There is also a Comment on PR GitHub Action. I had difficulties getting it running for PRs of contributors having read-only access only.

koppor avatar Nov 14 '20 20:11 koppor

I also found this issue while thinking about making the suggestion of (optionally) writing the output to a file. Like this, it would be possible to use an action like peter-evans/create-issue-from-file to automatically open an issue if a scheduled run found a broken link.

prcr avatar Dec 12 '20 21:12 prcr

If anyone is still interested in this I created an action to give you this information: Markdown Link Check log parser.

This action parses the log output from the Markdown Link Check action and makes it available in JSON or markdown format as a step output or as a file.

I've used this action in another repo of mine where I wanted to create an issue when broken link in markdown are found. Example: Markdown link check found broken links #496.

Hope this helps.

Image of the issue linked above

image

Image of the issue linked above - you can expand the files to see more information about the errors

image

Image of how it looks when adding to the Job Summary. Link to the pipeline.

image

edumserrano avatar Jul 03 '22 20:07 edumserrano

@gaurav-nelson would you consider adding the output you write to the step log as a step output? I understand your concerns, mainly around the potentially large step output but this could be enabled by an action input parameter? As in, have an action input like step-output which by default is false.

Doing this would allow me to adjust my Markdown Link Check log parser action to also accept the step output as an input ? It would also enable my action to run as part of the same workflow instead of having to create a separate workflow.

What do you think ?

edumserrano avatar Jul 09 '22 10:07 edumserrano

@edumserrano Thank you for working on this one. ❤️

Sure, I'll add it in my TODO's but feel free to create a PR. I have some questions:

  1. Should I also add https://github.com/gaurav-nelson/github-action-markdown-link-check/blob/master/entrypoint.sh#L45-L51 as step outputs?
  2. Since https://github.com/gaurav-nelson/github-action-markdown-link-check/blob/master/entrypoint.sh#L94 is a multiline file, Do you want me to set it as step output or an environment variable? PS: https://trstringer.com/github-actions-multiline-strings/

gaurav-nelson avatar Aug 08 '22 01:08 gaurav-nelson

@gaurav-nelson

1.Should I also add https://github.com/gaurav-nelson/github-action-markdown-link-check/blob/master/entrypoint.sh#L45-L51 as step outputs?

I don't need it for to be able to produce the output as shown in the comment above. That said, it might be good for other reasons right? If it's not too much I guess we could just add it as it might enable other scenarios right? On the other hand if it's problematic leave it as for an initial version of this work it's not needed.

2.Since https://github.com/gaurav-nelson/github-action-markdown-link-check/blob/master/entrypoint.sh#L94 is a multiline file, Do you want me to set it as step output or an environment variable? PS: https://trstringer.com/github-actions-multiline-strings/

For my request both ways would work. I feel like an action output is a better interface for consumers. At least I, when reading an action, always look for inputs and outputs. Sure the docs can let the consumer know that "hey, if you use this env variable you can also get X" but I feel that's just not the best experience.

I have also faced the issue described in your link with setting an action output step value that consists of multiline strings. The substitutions indicated did work for me and it's something you only need to do when setting the output on the step, not something you then need to reverse when getting the output from the step (the GitHub runner will take care of that for you).

What I'm trying to say is that this question is more for you than for me. Since you're the one that has to deal with doing the encoding when setting the multiline step output. For me I'll just get a multiline value when I access that step output variable from your action.

If it helps, for me it has been simple to do the substitutions required for multiline. In my workflows when I want to set a step output with multiline I do stuff like the below example. This example is a powershell script step that builds a multiline string from some runner info plus some file that has been previously created and then does the escaping to preserve the newlines before setting it as a step output:

$commentBody = "# [Test runs on ${{ matrix.os }}](${{ github.event.workflow_run.html_url }}) for commit ${{ github.event.workflow_run.head_sha }}`n`n"
$commentBody += Get-Content ./${{ env.TEST_RESULTS_ARTIFACT_NAME }}/*.md -Raw # without the -Raw the escaping that happens next does not work. Not sure why.
# The content must be escaped to preserve newlines. See https://github.community/t/set-output-truncates-multiline-strings/16852/3
$commentBody = $commentBody -replace "`n","%0A"
$commentBody = $commentBody -replace "`r","%0D"
Write-Output "::set-output name=pr-comment-body::$commentBody"

The number of escape rules you need to implement depend on the output you're producing. For instance I didn't have to do the MY_STRING="${MY_STRING//'%'/'%25'}" substitution because my output didn't need it.

Let me know if you have more doubts. Happy to help. Thank you for adding this to your TODO ❤️

edumserrano avatar Aug 08 '22 23:08 edumserrano