lycheeverse / lychee-action

Github action to check for broken links in Markdown, HTML, and text files using lychee, a fast link checker written in Rust.
https://lychee.cli.rs
Apache License 2.0
292 stars 39 forks source link

Bug: not possible to output JSON to file #198

Closed jasongitmail closed 1 year ago

jasongitmail commented 1 year ago

There seems to be bug that prevents outputting JSON to a file. Could it be the lack of INPUT_OUTPUT within action.yml, given it defaults the value of output currently to --output ${LYCHEE_TMP}?

My workaround is to run the lychee action step to install it, but then to follow with a separate step using lychee: - run: lychee <otherArgs> --format json --output ./links.json.

mre commented 1 year ago

Thanks for the report @jasongitmail!

We only wrote the output to file in case of error (exit code == 0).

I don't know why we did that. It's a remnant of the original (now deprecated) action code from link-checker: https://github.com/peter-evans/link-checker/blame/ce2cdf3d3f679dca05554c43f493821b878e1b4d/entrypoint.sh There probably was a good reason to do this in the old action, but for us, it's quite limiting, and so I removed that condition again.

Instead, we'll always write an output file now. Apologies for the inconvenience. You can test it by using lycheeverse/lychee-action@master and if all goes well, please report back. I'll release a new version then. ✌️

jasongitmail commented 1 year ago

Unfortunately, there seems to still be something awry.

I tested uses: lycheeverse/lychee-action@master

Then I also ran ls -la for a number of directories after running lychee-action to try to find the file, in case it saved somewhere unexpected, but it wasn't anywhere to be found. I also tried a filename that does not have a directory in the path, since my actual path contains a dir, in case that made a difference, but same result. I'm using the same command that otherwise works with lychee directly as the args for the action.

mre commented 1 year ago

Ah, so you overwrite --output, in your args right? So you have something like

- name: Link Checker
  uses: lycheeverse/lychee-action@master
  with:
    args: --output foo.txt ...

If so, this is a bit tricky, because it is currently not used. Instead, the recommended way is to set the additional output argument for the action and not set it in args:

- name: Link Checker
  uses: lycheeverse/lychee-action@master
  with:
    # Check all markdown and html files in repo (default)
    args: --verbose --no-progress './**/*.md' './**/*.html' './**/*.rst'
    # Use json as output format (instead of markdown)
    format: json
    # Use different output file path <-- That's what you're looking for
    output: /tmp/foo.json

This puts the output into /tmp/foo.json. The default is lychee/out.md, relative to the working directory of the action.

Can you try that?

If it's not possible, I can change it such that it uses --output from the args if it is set. This should avoid the confusion for users. We already do something similar for --format: https://github.com/lycheeverse/lychee-action/blob/5a5fc0bef7bcf1858217e7c9a8d4c01ec79dbeaf/entrypoint.sh#L18-L22

But first, I'd like to learn if setting output: /tmp/foo.json works for you.

If I misunderstood, can you paste your workflow here?

jasongitmail commented 1 year ago

Oh sorry, yeah let me try that. I was using the args version

jasongitmail commented 1 year ago

Working with that syntax! Thanks for the fix!

mre commented 1 year ago

Thanks for the feedback. 👍 Since this seems to be a common footgun, I might still change the entrypoint to also check args for the output parameter, as described above. #201