Skip to content

Commit

Permalink
Always create output file; not only on error (#199)
Browse files Browse the repository at this point in the history
We only create an output file in case the GitHub action run was not successful (exit code != 0). This commit changes that. We now unconditionally write an output file. Since the file should automatically be cleaned up after the run, there should be no negative side effects.
  • Loading branch information
mre authored Jun 30, 2023
1 parent 7cdbd64 commit e4b3f3d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
34 changes: 29 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ jobs:
continue-on-error: true
name: Test the lychee link checker action
steps:
# To use this repository's private action,
# we must check out the repository
- name: Checkout
uses: actions/checkout@v3

- name: test defaults
uses: ./
with:
fail: true

- name: test explicit lychee version
uses: ./
with:
lycheeVersion: 0.9.0

- name: test globs
uses: ./
with:
Expand All @@ -33,36 +34,59 @@ jobs:
'./**/*.html'
'./**/*.rst'
fail: true

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

- name: test workflow inputs - Markdown
uses: ./
with:
args: -v fixtures/TEST.md
format: json
output: /tmp/foo.json
output: ${{ github.workspace }}/foo_md.json
fail: true

- name: Validate JSON - Markdown
run: |
if ! jq empty ${{ github.workspace }}/foo_md.json; then
echo "Output file does not exist or is not valid JSON"
exit 1
fi
- name: test workflow inputs - rST
uses: ./
with:
args: -v fixtures/TEST.rst
format: json
output: /tmp/foo.json
output: ${{ github.workspace }}/foo_rst.json
fail: true

- name: Validate JSON - rST
run: |
if ! jq empty ${{ github.workspace }}/foo_rst.json; then
echo "Output file does not exist or is not valid JSON"
exit 1
fi
- name: directory
uses: ./
with:
args: --exclude-mail .
fail: true

- name: test format override
uses: ./
with:
args: --format markdown -v fixtures/TEST.md
format: doesnotexist # gets ignored if format set in args
output: /tmp/foo.txt
output: ${{ github.workspace }}/foo.txt
fail: true

- name: test debug
uses: ./
with:
debug: true

- name: test custom GitHub token
uses: ./
with:
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ runs:
steps:
- name: Install lychee
run: |
# Cleanup artifacts from previous run in case it crashed
rm -rf "lychee-v${{ inputs.LYCHEEVERSION }}-x86_64-unknown-linux-gnu.tar.gz" lychee
curl -sLO "https://github.com/lycheeverse/lychee/releases/download/v${{ inputs.LYCHEEVERSION }}/lychee-v${{ inputs.LYCHEEVERSION }}-x86_64-unknown-linux-gnu.tar.gz"
tar -xvzf "lychee-v${{ inputs.LYCHEEVERSION }}-x86_64-unknown-linux-gnu.tar.gz"
rm "lychee-v${{ inputs.LYCHEEVERSION }}-x86_64-unknown-linux-gnu.tar.gz"
Expand Down
8 changes: 4 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ if [ ! -f "${LYCHEE_TMP}" ]; then
echo "No output. Check pipeline run to see if lychee panicked." > "${LYCHEE_TMP}"
fi

# If link errors were found, create a report in the designated directory
if [ $exit_code -ne 0 ]; then
# If we have any output, create a report in the designated directory
if [ -f "${LYCHEE_TMP}" ]; then
mkdir -p "$(dirname -- "${INPUT_OUTPUT}")"
cat "${LYCHEE_TMP}" > "${INPUT_OUTPUT}"

Expand All @@ -52,8 +52,8 @@ fi
# Pass lychee exit code to next step
echo "lychee_exit_code=$exit_code" >> $GITHUB_ENV

# 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 `fail` is set to `true`, propagate the real exit code to the workflow
# runner. This will cause the pipeline to fail on `exit != 0`.
if [ "$INPUT_FAIL" = true ] ; then
exit ${exit_code}
fi
4 changes: 2 additions & 2 deletions fixtures/TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Some more complex formatting to test that Markdown parsing works.
[![CC0](https://i.creativecommons.org/p/zero/1.0/88x31.png)](https://creativecommons.org/publicdomain/zero/1.0/)

Test HTTP and HTTPS for the same site.
http://spinroot.com/cobra/
https://spinroot.com/cobra/
http://google.com/
https://google.com/

test@example.com

0 comments on commit e4b3f3d

Please sign in to comment.