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

[Feature] force to find at least X files to analyze #84

Closed
dkarlovi opened this issue Mar 1, 2022 · 3 comments
Closed

[Feature] force to find at least X files to analyze #84

dkarlovi opened this issue Mar 1, 2022 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@dkarlovi
Copy link

dkarlovi commented Mar 1, 2022

NOTE: This issue was moved from lychee to lychee-action


Was running my CI and lychee said all good, except I disabled the generation process and it found zero files to analyze. 🙈

It seems like it would be a good idea to be able to say

You must find at least X things to analyze, otherwise it's an error.

This avoids this output.

🔍 0 Total ✅ 0 OK 🚫 0 Errors

It would be opt-in, so by default the current behaviour remains.

Maybe something like --min-total=X or similar? Don't know if it would make sense to also have a test for maximum?

I expect no more than X files, anything more is a mistake.

@mre
Copy link
Member

mre commented Mar 1, 2022

Hum... I don't know of any other CLI tool that does that. I can see however that this is a good use-case for CI. We could add it to lychee-action. If someone adds a link checker and it can't find a single link that's probably a config mistake. Since it's enough for your use-case to tread 0 total links as an error, I'd probably rename the setting.

- name: Link Checker
  uses: lycheeverse/lychee-action@v1.3.1
  with:
    fail-if-empty: true

I don't know if we should turn this on by default.
What do you think about moving this issue to lychee-action?

@dkarlovi
Copy link
Author

dkarlovi commented Mar 1, 2022

Sounds good to me. 👍

@mre mre transferred this issue from lycheeverse/lychee Mar 1, 2022
@mre mre added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Mar 1, 2022
@mre
Copy link
Member

mre commented Jul 11, 2022

Thinking about this a little more, I don't know how to easily get the count of total links.

The lychee output depends on the --format argument. It can be markdown, json, or something else. For every format the way to extract the total number of links is different.
I was thinking about doing a lychee --dump | wc -l before the actual run in case fail-if-empty is set to true. It should be quite fast and only affect users, which have that feature enabled. Probably we don't want to enable it by default, though.

New workflow syntax (camelCase arguments):

- name: Link Checker
  uses: lycheeverse/lychee-action@v1.3.1
  with:
    failIfEmpty: true # default: false

Condition inside entrypoint.sh:

# Lychee error code for link check errors.
# Used to exit early in case of empty input.
LINK_CHECK_ERROR_EXIT_CODE=2

if [ "${INPUT_CHECK_IF_EMPTY}" == true ]; then
  link_count=$(eval lychee --dump ${ARGS} | wc -l)
  if [ "${link_count}" -eq "0" ]; then
    exit ${LINK_CHECK_ERROR_EXIT_CODE}
  fi
fi

@mre mre closed this as completed in ad3b13a Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants