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

Bug: not possible to output JSON to file #198

Closed
jasongitmail opened this issue Jun 23, 2023 · 6 comments
Closed

Bug: not possible to output JSON to file #198

jasongitmail opened this issue Jun 23, 2023 · 6 comments

Comments

@jasongitmail
Copy link

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

mre commented Jun 30, 2023

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

jasongitmail commented Jul 3, 2023

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

mre commented Jul 4, 2023

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:

ARGS="${INPUT_ARGS}"
FORMAT=""
# Backwards compatibility:
# If `format` occurs in args, ignore the value from `INPUT_FORMAT`
[[ "$ARGS" =~ "--format " ]] || FORMAT="--format ${INPUT_FORMAT}"

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

jasongitmail commented Jul 4, 2023

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

@jasongitmail
Copy link
Author

jasongitmail commented Jul 5, 2023

Working with that syntax! Thanks for the fix!

@mre
Copy link
Member

mre commented Jul 5, 2023

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

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

2 participants