diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 44373ba..03bc2b4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ 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 @@ -57,7 +57,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 }}" @@ -68,13 +68,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 }}" @@ -92,7 +92,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 }}" @@ -104,6 +104,27 @@ 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 + + # 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 diff --git a/action.yml b/action.yml index b06c67b..6edca44 100644 --- a/action.yml +++ b/action.yml @@ -14,7 +14,7 @@ inputs: default: false required: false failIfEmpty: - description: "fail entire pipeline if no links were found" + description: "Fail entire pipeline if no links were found" default: true required: false format: @@ -64,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 }} diff --git a/entrypoint.sh b/entrypoint.sh index 3459510..fcf0eb8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -27,9 +27,9 @@ 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:-false}" = "true" ]; then +if [ "${INPUT_FAILIFEMPTY}" = "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 + 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 diff --git a/fixtures/empty.md b/fixtures/empty.md new file mode 100644 index 0000000..9e30fc1 --- /dev/null +++ b/fixtures/empty.md @@ -0,0 +1 @@ +This file contains no links. Used for checking `failIfEmpty` flag. \ No newline at end of file