Skip to content

Commit

Permalink
Add fail if empty argument
Browse files Browse the repository at this point in the history
If no links were found during a run, this could indicate a configuration
issue. In order to warn users, this new option allows failing the pipeline
in such a scenario.
  • Loading branch information
mre committed Mar 2, 2022
1 parent f0cc808 commit 1774a4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ inputs:
description: "output file"
default: "lychee/out.md"
required: false
fail-if-empty:
description: "fail entire pipeline if no links were found"
default: true
required: false
fail:
description: "fail entire pipeline on error (exit code not 0)"
default: false
Expand Down
13 changes: 12 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ if [ ! -f "${LYCHEE_TMP}" ]; then
echo "No output. Check pipeline run to see if lychee panicked." > "${LYCHEE_TMP}"
fi

# Overwrite the error code in case no links were found
# and `fail-if-empty` is set to `true` (and it is by default)
if [ "${INPUT_FAIL_IF_EMPTY}" = true ]; then
# This is a somewhat crude way to check the Markdown output of lychee
if echo "${LYCHEE_TMP}" | grep -E 'Total\s+\|\s+0'; then
echo "No links were found. This usually indicates a configuration error." >> "${LYCHEE_TMP}"
echo "If this was expected, set 'fail-if-empty: true' in the args." >> "${LYCHEE_TMP}"
exit_code=1
fi
fi

# If link errors were found, create a report in the designated directory
if [ $exit_code -ne 0 ]; then
mkdir -p "$(dirname -- "${INPUT_OUTPUT}")"
Expand All @@ -37,6 +48,6 @@ echo ::set-output name=exit_code::$exit_code

# If `fail` is set to `true`, propagate the real exit value to the workflow
# runner. This will cause the pipeline to fail on exit != 0.
if [ "$INPUT_FAIL" = true ] ; then
if [ "$INPUT_FAIL" = true ]; then
exit ${exit_code}
fi

0 comments on commit 1774a4f

Please sign in to comment.