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

Add failIfEmpty argument (fixes #84) #86

Merged
merged 8 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
on:
- repository_dispatch
- workflow_dispatch
- push
- pull_request
push:
branches:
- master
pull_request:
workflow_dispatch:
repository_dispatch:

env:
CUSTOM_OUTPUT_RELATIVE_PATH: lychee/custom_output.md
CUSTOM_OUTPUT_ABSOLUTE_PATH: /tmp/report.md
CUSTOM_OUTPUT_DUMP_PATH: /tmp/dump.md

jobs:
lychee-action:
runs-on: ubuntu-latest
continue-on-error: true
name: Test the lychee link checker action
steps:
- name: Checkout
Expand Down Expand Up @@ -57,7 +58,7 @@ jobs:
with:
output: "${{ env.CUSTOM_OUTPUT_RELATIVE_PATH }}"
debug: true

- name: test custom output relative path - validation
run: |
echo "Checking custom output file at ${{ env.CUSTOM_OUTPUT_RELATIVE_PATH }}"
Expand All @@ -68,13 +69,13 @@ jobs:
echo "Found. Contents:"
cat "${{ env.CUSTOM_OUTPUT_RELATIVE_PATH }}"
fi

- name: test custom output absolute path - creation
uses: ./
with:
output: "${{ env.CUSTOM_OUTPUT_ABSOLUTE_PATH }}"
debug: true

- name: test custom output absolute path - validation
run: |
echo "Checking custom output file at ${{ env.CUSTOM_OUTPUT_ABSOLUTE_PATH }}"
Expand All @@ -92,7 +93,7 @@ jobs:
args: --dump './**/*.md' './**/*.html' './**/*.rst'
output: "${{ env.CUSTOM_OUTPUT_DUMP_PATH }}"
debug: true

- name: test dump with custom output path - validation
run: |
echo "Checking dump output file at ${{ env.CUSTOM_OUTPUT_DUMP_PATH }}"
Expand All @@ -104,6 +105,28 @@ jobs:
cat "${{ env.CUSTOM_OUTPUT_DUMP_PATH }}"
fi

- name: test failIfEmpty - no links in input should fail the pipeline
id: fail_if_empty_test
uses: ./
with:
args: --verbose --no-progress fixtures/empty.md
debug: true
continue-on-error: true

# Explictly check the exit code of the previous step
# as it's expected to fail
- name: Check failIfEmpty
if: steps.fail_if_empty_test.outcome != 'failure'
run: |
echo "FailIfEmpty should have failed because no links were found."
exit 1

- name: test disable failIfEmpty - it's okay if no links are found
uses: ./
with:
args: --no-progress fixtures/empty.md
failIfEmpty: false

- name: Install jq
run: sudo apt-get install jq

Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ inputs:
description: "Fail entire pipeline on error (i.e. when lychee exit code is not 0)"
default: false
required: false
failIfEmpty:
description: "Fail entire pipeline if no links were found"
default: true
required: false
format:
description: "Summary output format (e.g. json)"
default: "markdown"
Expand All @@ -30,7 +34,7 @@ inputs:
default: "lychee/out.md"
required: false
token:
description: 'Your GitHub Access Token, defaults to: {{ github.token }}'
description: "Your GitHub Access Token, defaults to: {{ github.token }}"
default: ${{ github.token }}
required: false
outputs:
Expand Down Expand Up @@ -60,6 +64,7 @@ runs:
INPUT_ARGS: ${{ inputs.ARGS }}
INPUT_DEBUG: ${{ inputs.DEBUG }}
INPUT_FAIL: ${{ inputs.FAIL }}
INPUT_FAILIFEMPTY: ${{ inputs.FAILIFEMPTY }}
INPUT_FORMAT: ${{ inputs.FORMAT }}
INPUT_JOBSUMMARY: ${{ inputs.JOBSUMMARY }}
INPUT_OUTPUT: ${{ inputs.OUTPUT }}
Expand Down
14 changes: 14 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ FORMAT=""
eval lychee ${FORMAT} --output ${LYCHEE_TMP} ${ARGS}
exit_code=$?

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

if [ ! -f "${LYCHEE_TMP}" ]; then
echo "No output. Check pipeline run to see if lychee panicked." > "${LYCHEE_TMP}"
else
Expand Down
1 change: 1 addition & 0 deletions fixtures/empty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file contains no links. Used for checking `failIfEmpty` flag.
Loading