From 7c151a7e82417d3e8e86b7ddfaecf939df2c5549 Mon Sep 17 00:00:00 2001 From: Matthias Endler Date: Mon, 7 Oct 2024 11:42:55 +0200 Subject: [PATCH 1/7] Split up steps in action This helps with making the code more debuggable/maintainable --- action.yml | 54 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/action.yml b/action.yml index 535e0e8..a3909b3 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,6 @@ name: "Lychee Broken Link Checker" description: "Quickly check links in Markdown, HTML, and text files" + inputs: args: description: "Lychee arguments (https://github.com/lycheeverse/lychee#commandline-parameters)" @@ -37,32 +38,56 @@ inputs: description: "Your GitHub Access Token, defaults to: {{ github.token }}" default: ${{ github.token }} required: false + outputs: exit_code: description: "The exit code returned from Lychee" - value: ${{ steps.lychee.outputs.exit_code }} + value: ${{ steps.run-lychee.outputs.exit_code }} + runs: using: "composite" steps: - - name: Install lychee + - name: Set up environment + run: | + echo "$HOME/.local/bin" >> "$GITHUB_PATH" + mkdir -p "$HOME/.local/bin" + shell: bash + + - name: Determine Lychee filename + id: lychee-filename + run: | + if [[ '${{ inputs.lycheeVersion }}' =~ ^v0\.0|^v0\.1[0-5]\. ]]; then + echo "filename=lychee-${{ inputs.lycheeVersion }}-x86_64-unknown-linux-gnu.tar.gz" >> $GITHUB_OUTPUT + else + echo "filename=lychee-x86_64-unknown-linux-gnu.tar.gz" >> $GITHUB_OUTPUT + fi + shell: bash + + - name: Download Lychee + run: | + curl -sfLO "https://github.com/lycheeverse/lychee/releases/download/${{ inputs.lycheeVersion }}/${{ steps.lychee-filename.outputs.filename }}" + shell: bash + + - name: Extract Lychee + run: | + tar -xvzf "${{ steps.lychee-filename.outputs.filename }}" + shell: bash + + - name: Install Lychee run: | - # Cleanup artifacts from previous run in case it crashed - rm -rf "lychee-${{ inputs.LYCHEEVERSION }}-x86_64-unknown-linux-gnu.tar.gz" lychee - case '${{ inputs.LYCHEEVERSION }}' in - v0.0*|v0.1[0-5].*) filename='lychee-${{ inputs.LYCHEEVERSION }}-x86_64-unknown-linux-gnu.tar.gz';; - *) filename='lychee-x86_64-unknown-linux-gnu.tar.gz' - esac - curl -sfLO "https://github.com/lycheeverse/lychee/releases/download/${{ inputs.LYCHEEVERSION }}/$filename" - tar -xvzf "$filename" - rm "$filename" install -t "$HOME/.local/bin" -D lychee + shell: bash + + - name: Clean up installation files + run: | + rm -f "${{ steps.lychee-filename.outputs.filename }}" shopt -s extglob rm -f lychee*!(lychee-bin|lychee-lib) - echo "$HOME/.local/bin" >> "$GITHUB_PATH" shell: bash - - name: Run lychee - run: ${{ github.action_path }}/entrypoint.sh + + - name: Run Lychee id: lychee + run: ${{ github.action_path }}/entrypoint.sh env: # https://github.com/actions/runner/issues/665 INPUT_TOKEN: ${{ inputs.TOKEN }} @@ -74,6 +99,7 @@ runs: INPUT_JOBSUMMARY: ${{ inputs.JOBSUMMARY }} INPUT_OUTPUT: ${{ inputs.OUTPUT }} shell: bash + branding: icon: "external-link" color: "purple" From 28b9767093c01b373b26d181ca00d128c202dd37 Mon Sep 17 00:00:00 2001 From: Matthias Endler Date: Mon, 7 Oct 2024 11:50:17 +0200 Subject: [PATCH 2/7] Add back cleanup step to beginning --- action.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index a3909b3..0275950 100644 --- a/action.yml +++ b/action.yml @@ -53,7 +53,7 @@ runs: mkdir -p "$HOME/.local/bin" shell: bash - - name: Determine Lychee filename + - name: Determine lychee filename id: lychee-filename run: | if [[ '${{ inputs.lycheeVersion }}' =~ ^v0\.0|^v0\.1[0-5]\. ]]; then @@ -63,29 +63,38 @@ runs: fi shell: bash - - name: Download Lychee + - name: Clean up existing lychee files + run: | + # Remove any existing lychee binaries or archives to prevent conflicts + rm -f "$HOME/.local/bin/lychee" + rm -f lychee + rm -f "${{ steps.lychee-filename.outputs.filename }}" + shell: bash + + - name: Download lychee run: | curl -sfLO "https://github.com/lycheeverse/lychee/releases/download/${{ inputs.lycheeVersion }}/${{ steps.lychee-filename.outputs.filename }}" shell: bash - - name: Extract Lychee + - name: Extract lychee run: | tar -xvzf "${{ steps.lychee-filename.outputs.filename }}" shell: bash - - name: Install Lychee + - name: Install lychee run: | install -t "$HOME/.local/bin" -D lychee shell: bash - name: Clean up installation files run: | + # Remove the downloaded archive and any unnecessary files after installation rm -f "${{ steps.lychee-filename.outputs.filename }}" shopt -s extglob rm -f lychee*!(lychee-bin|lychee-lib) shell: bash - - name: Run Lychee + - name: Run lychee id: lychee run: ${{ github.action_path }}/entrypoint.sh env: @@ -99,7 +108,6 @@ runs: INPUT_JOBSUMMARY: ${{ inputs.JOBSUMMARY }} INPUT_OUTPUT: ${{ inputs.OUTPUT }} shell: bash - branding: icon: "external-link" color: "purple" From 00bb447777df5fe762b31be7616561e3ee6df540 Mon Sep 17 00:00:00 2001 From: Matthias Endler Date: Mon, 7 Oct 2024 11:51:42 +0200 Subject: [PATCH 3/7] Fix cleanup --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 0275950..cdd1a78 100644 --- a/action.yml +++ b/action.yml @@ -67,7 +67,7 @@ runs: run: | # Remove any existing lychee binaries or archives to prevent conflicts rm -f "$HOME/.local/bin/lychee" - rm -f lychee + rm -rf lychee rm -f "${{ steps.lychee-filename.outputs.filename }}" shell: bash From adcc32350970a98256288e4674817b4bde7fe9f8 Mon Sep 17 00:00:00 2001 From: Matthias Endler Date: Mon, 7 Oct 2024 12:01:03 +0200 Subject: [PATCH 4/7] Propagate exit code --- action.yml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index cdd1a78..87bca77 100644 --- a/action.yml +++ b/action.yml @@ -94,9 +94,22 @@ runs: rm -f lychee*!(lychee-bin|lychee-lib) shell: bash - - name: Run lychee - id: lychee - run: ${{ github.action_path }}/entrypoint.sh + - name: Run Lychee + id: run-lychee + run: | + # This step runs lychee and captures its exit code. + # We use 'set +e' to prevent the script from exiting immediately if lychee fails. + # This allows us to capture the exit code and pass it both to GitHub Actions (via GITHUB_OUTPUT) + # and to the shell (via the final 'exit $EXIT_CODE'). + # This ensures that: + # 1. The step fails if lychee fails + # 2. The exit code is available as an output for subsequent steps + # 3. The exit code is properly propagated to the workflow + set +e + ${{ github.action_path }}/entrypoint.sh + EXIT_CODE=$? + echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT + exit $EXIT_CODE env: # https://github.com/actions/runner/issues/665 INPUT_TOKEN: ${{ inputs.TOKEN }} From e7546ad05799e68acfb2f6fd22db65c6a8f80499 Mon Sep 17 00:00:00 2001 From: Matthias Endler Date: Mon, 7 Oct 2024 12:05:54 +0200 Subject: [PATCH 5/7] Add comment about lychee filename --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index 87bca77..4e4b6d5 100644 --- a/action.yml +++ b/action.yml @@ -56,6 +56,8 @@ runs: - name: Determine lychee filename id: lychee-filename run: | + # Older releases (prior to 0.16.x) had the version number in the archive name. + # This determines the correct filename based on the version string. if [[ '${{ inputs.lycheeVersion }}' =~ ^v0\.0|^v0\.1[0-5]\. ]]; then echo "filename=lychee-${{ inputs.lycheeVersion }}-x86_64-unknown-linux-gnu.tar.gz" >> $GITHUB_OUTPUT else From 9bdee7dd13eae2a3a6adb5e34f2bba861316cf57 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 7 Oct 2024 12:24:08 +0200 Subject: [PATCH 6/7] Bump version to 0.16.x, respect new tag names With 0.16.x, we started to release the lychee CLI binary separately from the lychee library. As a consequence, the crates get prefixed differently on GitHub releases: - CLI binary: `lychee-v0.16.0` - Library: `lychee-lib-v0.16.0` We need to account for that when downloading the binary, as shown in this commit. --- action.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 4e4b6d5..6d22d74 100644 --- a/action.yml +++ b/action.yml @@ -28,7 +28,7 @@ inputs: required: false lycheeVersion: description: "Use custom version of lychee link checker" - default: v0.15.0 + default: v0.16.1 required: false output: description: "Summary output file path" @@ -60,8 +60,17 @@ runs: # This determines the correct filename based on the version string. if [[ '${{ inputs.lycheeVersion }}' =~ ^v0\.0|^v0\.1[0-5]\. ]]; then echo "filename=lychee-${{ inputs.lycheeVersion }}-x86_64-unknown-linux-gnu.tar.gz" >> $GITHUB_OUTPUT + echo "tag=${{ inputs.lycheeVersion }}" >> $GITHUB_OUTPUT else echo "filename=lychee-x86_64-unknown-linux-gnu.tar.gz" >> $GITHUB_OUTPUT + # Each crate in the workspace has its own tag, so we need to specify the tag for the binary. + # The binary is released under the 'lychee' tag, the library under 'lychee-lib'. + # For nightly builds, we use the 'nightly' tag. + if [[ '${{ inputs.lycheeVersion }}' == 'nightly' ]]; then + echo "tag=${{ inputs.lycheeVersion }}" >> $GITHUB_OUTPUT + else + echo "tag=lychee-${{ inputs.lycheeVersion }}" >> $GITHUB_OUTPUT + fi fi shell: bash @@ -75,7 +84,7 @@ runs: - name: Download lychee run: | - curl -sfLO "https://github.com/lycheeverse/lychee/releases/download/${{ inputs.lycheeVersion }}/${{ steps.lychee-filename.outputs.filename }}" + curl -sfLO "https://github.com/lycheeverse/lychee/releases/download/${{ steps.lychee-filename.outputs.tag }}/${{ steps.lychee-filename.outputs.filename }}" shell: bash - name: Extract lychee From da656affc792a2f7760fee30db836859843f9fb4 Mon Sep 17 00:00:00 2001 From: Matthias Endler Date: Mon, 7 Oct 2024 13:04:47 +0200 Subject: [PATCH 7/7] fix tag --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 8a678fa..6d22d74 100644 --- a/action.yml +++ b/action.yml @@ -84,7 +84,7 @@ runs: - name: Download lychee run: | - curl -sfLO "https://github.com/lycheeverse/lychee/releases/download/${{ inputs.lycheeVersion }}/${{ steps.lychee-filename.outputs.filename }}" + curl -sfLO "https://github.com/lycheeverse/lychee/releases/download/${{ steps.lychee-filename.outputs.tag }}/${{ steps.lychee-filename.outputs.filename }}" shell: bash - name: Extract lychee