From e4b3f3d101978933dd3e111a47d6702a50e51a87 Mon Sep 17 00:00:00 2001 From: Matthias Endler Date: Fri, 30 Jun 2023 14:28:26 +0200 Subject: [PATCH] Always create output file; not only on error (#199) 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. --- .github/workflows/test.yml | 34 +++++++++++++++++++++++++++++----- action.yml | 2 ++ entrypoint.sh | 8 ++++---- fixtures/TEST.md | 4 ++-- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e17ea5d..b88fdf3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: @@ -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: diff --git a/action.yml b/action.yml index 3c6f4e2..788201e 100644 --- a/action.yml +++ b/action.yml @@ -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" diff --git a/entrypoint.sh b/entrypoint.sh index 64601bf..bfd46a5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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}" @@ -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 diff --git a/fixtures/TEST.md b/fixtures/TEST.md index 7ec8769..9f7971a 100644 --- a/fixtures/TEST.md +++ b/fixtures/TEST.md @@ -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