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

How to --dump to file? #214

Closed
tooomm opened this issue Oct 29, 2023 · 11 comments · Fixed by #215
Closed

How to --dump to file? #214

tooomm opened this issue Oct 29, 2023 · 11 comments · Fixed by #215

Comments

@tooomm
Copy link
Contributor

tooomm commented Oct 29, 2023

It looks like --dump only prints the found links to the console.

I would like to dump the extracted links to a file to further work with it.
Not sure how to do this with the action.

output: is not considered, or I'm not sure of the actual location 🤔

@mre
Copy link
Member

mre commented Nov 30, 2023

Yeah, that's a bug in lychee then. It should consider the output setting. Let me move that over to the main repo.

@mre mre transferred this issue from lycheeverse/lychee-action Nov 30, 2023
@mre
Copy link
Member

mre commented Nov 30, 2023

Actually I'm confused. It should work:

https://github.com/lycheeverse/lychee/blob/11d8d448953d85300f2a5b22815cc0d310bd7ff2/lychee-bin/src/commands/dump.rs#L21C9-L30

This has always been the case, ever since we supported dumping links in the first place.
lycheeverse/lychee@35ccfb8

@tooomm
Copy link
Contributor Author

tooomm commented Dec 3, 2023

Hmm, did you make it work with you GH Action?
As I noted, I might just don't know where the file ends up and how to properly call it from the action.

If you've an example at hand that would be awesome!

@mre mre transferred this issue from lycheeverse/lychee Dec 4, 2023
@mre
Copy link
Member

mre commented Dec 4, 2023

Whoops, then let me move it back to lychee-action. Apologies for the confusion.
You can decide where the file ends up in the action.

- name: Link Checker
  uses: lycheeverse/lychee-action@master
  with:
    # Check all markdown and html files in repo (default)
    args: --base . --dump './**/*.md' './**/*.html' './**/*.rst'
    # Use different output file path
    output: /tmp/foo.txt

The default path currently is lychee/out.md (as defined in the action.yml).
If the output does not end up there, that's a bug.

To reuse the output in a downstream job that depends on this job, see "Defining outputs for jobs" in the GitHub Docs.

@tooomm
Copy link
Contributor Author

tooomm commented Dec 10, 2023

Thanks again for trying to help here, mre!

You can decide where the file ends up in the action.

That's correct.
As stated in the issue description, I was using output and was not able to spot the file when trying various possibilities.
Same actually, when using the default location and not using a custom path for output.

So the question is still the same... :D
Can not tell if it's a bug or me being the issue here.

To reuse the output in a downstream job that depends on this job, see "Defining outputs for jobs" in the GitHub Docs.

It should only be used in a subsequent step within the same job.

Can you provide me a working example that e.g. prints the file afterwards in a following step in the action?
Taking your above example here, how to print the foo.txt file for example... I could not find/link the file in my tests.

jobs:
  test-job:
    runs-on: ubuntu-latest
    steps:
      - name: Dump Output
        uses: lycheeverse/lychee-action@v1
        with:
          # Check all markdown and html files in repo (default)
          args: --base . --dump './**/*.md' './**/*.html' './**/*.rst'
          # Use different output file path
          output: /tmp/foo.txt
    
      - name: Print Output
        shell: bash
        run: cat ???

@mre
Copy link
Member

mre commented Dec 11, 2023

Hum, I don't know the answer. This doesn't work at least:

name: Links

on:
  workflow_dispatch:

jobs:
  linkChecker:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Dump Output
        uses: lycheeverse/lychee-action@v1.8.0
        with:
          args: --dump './**/*.md' './**/*.html' './**/*.rst'
          output: ./lychee/out.md
          debug: true

      - name: Print Output
        run: cat ./lychee/out.md

Output:

Run cat ./lychee/out.md
cat: ./lychee/out.md: No such file or directory
Error: Process completed with exit code 1.

I've added the debug flag. Maybe that helps to troubleshoot the issue.

@joryirving
Copy link
Contributor

So I'm running into a similar situation, where when I pass in the output command, it fails: https://github.com/LilDrunkenSmurf/k3s-home-cluster/actions/runs/7309944973/job/19918081978#step:4:110
I setup debug, and tried to print the output, and I noticed it's not evaluating the second if statement here:

if [ -f "${LYCHEE_TMP}" ]; then

It looks like it runs the if statement above, , and evaluates it to false, and carries on, but skips the next one.

Rather than making it two different if statements, perhaps it should be nested.

Something like:

# Ensure we have any output
if [ ! -f "${LYCHEE_TMP}" ]; then
    echo "No output. Check pipeline run to see if lychee panicked." > "${LYCHEE_TMP}"
else if
	# If we have any output, create a report in the designated directory
    mkdir -p "$(dirname -- "${INPUT_OUTPUT}")"
    cat "${LYCHEE_TMP}" > "${INPUT_OUTPUT}"

    if [ "${INPUT_FORMAT}" == "markdown" ]; then
        echo "[Full Github Actions output](${GITHUB_WORKFLOW_URL})" >> "${INPUT_OUTPUT}"
	fi
fi

@mre
Copy link
Member

mre commented Dec 24, 2023

Cool. Can you send a pull request with that change, so we can test it?

@joryirving
Copy link
Contributor

Tested the PR, and it looks good.

@mre mre closed this as completed in #215 Jan 5, 2024
@mre
Copy link
Member

mre commented Jan 5, 2024

@LilDrunkenSmurf fixed it in #215. Thanks!
We've also added an integration test in #217 to make sure it doesn't break in the future.
@tooomm fyi.

@mre
Copy link
Member

mre commented Jan 5, 2024

Also added an integration test for --dump specifically. #218

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

Successfully merging a pull request may close this issue.

3 participants