8000 Add test · lycheeverse/lychee-action@d4d9def · GitHub
[go: up one dir, main page]

Skip to content

Commit d4d9def

Browse files
committed
Add test
1 parent 4c4e89b commit d4d9def

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

.github/workflows/test.yml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ env:
88
CUSTOM_OUTPUT_RELATIVE_PATH: lychee/custom_output.md
99
CUSTOM_OUTPUT_ABSOLUTE_PATH: /tmp/report.md
1010
CUSTOM_OUTPUT_DUMP_PATH: /tmp/dump.md
11-
11+
1212
jobs:
1313
lychee-action:
1414
runs-on: ubuntu-latest
@@ -57,7 +57,7 @@ jobs:
5757
with:
5858
output: "${{ env.CUSTOM_OUTPUT_RELATIVE_PATH }}"
5959
debug: true
60-
60+
6161
- name: test custom output relative path - validation
6262
run: |
6363
echo "Checking custom output file at ${{ env.CUSTOM_OUTPUT_RELATIVE_PATH }}"
@@ -68,13 +68,13 @@ jobs:
6868
echo "Found. Contents:"
6969
cat "${{ env.CUSTOM_OUTPUT_RELATIVE_PATH }}"
7070
fi
71-
71+
7272
- name: test custom output absolute path - creation
7373
uses: ./
7474
with:
7575
output: "${{ env.CUSTOM_OUTPUT_ABSOLUTE_PATH }}"
7676
debug: true
77-
77+
7878
- name: test custom output absolute path - validation
7979
run: |
8080
echo "Checking custom output file at ${{ env.CUSTOM_OUTPUT_ABSOLUTE_PATH }}"
@@ -92,7 +92,7 @@ jobs:
9292
args: --dump './**/*.md' './**/*.html' './**/*.rst'
9393
output: "${{ env.CUSTOM_OUTPUT_DUMP_PATH }}"
9494
debug: true
95-
95+
9696
- name: test dump with custom output path - validation
9797
run: |
9898
echo "Checking dump output file at ${{ env.CUSTOM_OUTPUT_DUMP_PATH }}"
@@ -104,6 +104,27 @@ jobs:
104104
cat "${{ env.CUSTOM_OUTPUT_DUMP_PATH }}"
105105
fi
106106
107+
- name: test failIfEmpty - no links in input should fail the pipeline
108+
id: fail_if_empty_test
109+
uses: ./
110+
with:
111+
args: --verbose --no-progress fixtures/empty.md
112+
debug: true
113+
114+
# Explictly check the exit code of the previous step
115+
# as it's expected to fail
116+
- name: Check failIfEmpty
117+
if: steps.fail_if_empty_test.outcome != 'failure'
118+
run: |
119+
echo "FailIfEmpty should have failed because no links were found."
120+
exit 1
121+
122+
- name: test disable failIfEmpty - it's okay if no links are found
123+
uses: ./
124+
with:
125+
args: --no-progress fixtures/empty.md
126+
failIfEmpty: false
127+
107128
- name: Install jq
108129
run: sudo apt-get install jq
109130

action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ inputs:
1414
default: false
1515
required: false
1616
failIfEmpty:
17-
description: "fail entire pipeline if no links were found"
17+
description: "Fail entire pipeline if no links were found"
1818
default: true
1919
required: false
2020
format:
@@ -64,6 +64,7 @@ runs:
6464
INPUT_ARGS: ${{ inputs.ARGS }}
6565
INPUT_DEBUG: ${{ inputs.DEBUG }}
6666
INPUT_FAIL: ${{ inputs.FAIL }}
67+
INPUT_FAILIFEMPTY: ${{ inputs.FAILIFEMPTY }}
6768
INPUT_FORMAT: ${{ inputs.FORMAT }}
6869
INPUT_JOBSUMMARY: ${{ inputs.JOBSUMMARY }}
6970
INPUT_OUTPUT: ${{ inputs.OUTPUT }}

entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ exit_code=$?
2727

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

fixtures/empty.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file contains no links. Used for checking `failIfEmpty` flag.

0 commit comments

Comments
 (0)
0