├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ ├── auto-merge.yml │ ├── links.yml │ ├── lychee-version.yml │ ├── test.yml │ ├── test_cache.yml │ └── versioning.yml ├── .lycheeignore ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── SECURITY.md ├── action.yml ├── entrypoint.sh └── fixtures ├── TEST.md ├── TEST.rst ├── awesome.png ├── empty.md └── subdir └── test-working-dir.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | open_collective: lychee-collective 2 | github: mre 3 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | updates: 4 | 5 | # Keep dependencies for GitHub Actions up-to-date 6 | - package-ecosystem: 'github-actions' 7 | directory: '/' 8 | schedule: 9 | interval: 'daily' 10 | -------------------------------------------------------------------------------- /.github/workflows/auto-merge.yml: -------------------------------------------------------------------------------- 1 | name: 'Merge Dependencies' 2 | 3 | on: 4 | pull_request: 5 | 6 | jobs: 7 | auto-merge: 8 | runs-on: ubuntu-latest 9 | if: github.actor == 'dependabot[bot]' 10 | steps: 11 | - uses: actions/checkout@v4 12 | - uses: ahmadnassri/action-dependabot-auto-merge@v2.6.6 13 | with: 14 | github-token: ${{ secrets.AUTOMERGE_TOKEN }} 15 | # Merge all updates as long as they pass CI. 16 | # Includes minor and patch updates. 17 | update_type: "semver:major" 18 | -------------------------------------------------------------------------------- /.github/workflows/links.yml: -------------------------------------------------------------------------------- 1 | name: Links 2 | 3 | on: 4 | repository_dispatch: 5 | workflow_dispatch: 6 | schedule: 7 | - cron: "00 18 * * *" 8 | 9 | jobs: 10 | linkChecker: 11 | runs-on: ubuntu-latest 12 | permissions: 13 | issues: write # required for peter-evans/create-issue-from-file 14 | steps: 15 | - uses: actions/checkout@v4 16 | 17 | - name: Link Checker 18 | id: lychee 19 | uses: ./ # Uses an action in the root directory 20 | with: 21 | args: --user-agent "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0" --verbose --exclude spinroot.com --no-progress './**/*.md' './**/*.html' './**/*.rst' 22 | fail: true 23 | env: 24 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 25 | 26 | - name: Create Issue From File 27 | if: steps.lychee.outputs.exit_code != 0 28 | uses: peter-evans/create-issue-from-file@v5 29 | with: 30 | title: Link Checker Report 31 | content-filepath: ./lychee/out.md 32 | labels: report, automated issue 33 | -------------------------------------------------------------------------------- /.github/workflows/lychee-version.yml: -------------------------------------------------------------------------------- 1 | name: "Update Lychee Default Version" 2 | 3 | on: 4 | schedule: 5 | - cron: "0 0 * * 0" # every Sunday 6 | workflow_dispatch: 7 | repository_dispatch: 8 | 9 | jobs: 10 | check-lychee-version: 11 | runs-on: ubuntu-latest 12 | 13 | outputs: 14 | mismatch: ${{ steps.compare-versions.outputs.mismatch }} 15 | action_lychee_version: ${{ steps.get-action-lychee-version.outputs.result }} 16 | release_version: ${{ steps.get-lychee-release.outputs.release_version }} 17 | 18 | name: Check lychee version 19 | steps: 20 | - name: Checkout repository 21 | uses: actions/checkout@v4 22 | 23 | - name: Get current lychee release version 24 | id: get-lychee-release 25 | run: | 26 | echo "Fetching the latest lychee release version..." 27 | release=$(curl -s https://api.github.com/repos/lycheeverse/lychee/releases/latest | jq -r .tag_name) 28 | release=${release#lychee-} # Strip the 'lychee-' prefix 29 | echo "Latest release version fetched: $release" 30 | echo "release_version=$release" >> $GITHUB_OUTPUT 31 | 32 | - name: Extract lycheeVersion from action.yml 33 | id: get-action-lychee-version 34 | uses: mikefarah/yq@master 35 | with: 36 | cmd: yq '.inputs.lycheeVersion.default' action.yml 37 | 38 | - name: Compare versions 39 | id: compare-versions 40 | run: | 41 | echo "Comparing versions..." 42 | action_lychee_version="${{ steps.get-action-lychee-version.outputs.result }}" 43 | release_version="${{ steps.get-lychee-release.outputs.release_version }}" 44 | echo "Action lychee version: $action_lychee_version" 45 | echo "Latest release version: $release_version" 46 | if [ "$action_lychee_version" != "$release_version" ]; then 47 | echo "Versions do not match. Setting mismatch to true." 48 | echo "mismatch=true" >> $GITHUB_OUTPUT 49 | else 50 | echo "Versions match. Setting mismatch to false." 51 | echo "mismatch=false" >> $GITHUB_OUTPUT 52 | fi 53 | 54 | create-pr: 55 | permissions: 56 | contents: write 57 | pull-requests: write 58 | 59 | needs: check-lychee-version 60 | runs-on: ubuntu-latest 61 | if: needs.check-lychee-version.outputs.mismatch == 'true' 62 | 63 | name: Create PR to update lychee version 64 | env: 65 | action_lychee_version: ${{ needs.check-lychee-version.outputs.action_lychee_version }} 66 | release_version: ${{ needs.check-lychee-version.outputs.release_version }} 67 | update_branch_name: "update-lychee-${{ needs.check-lychee-version.outputs.release_version }}" 68 | 69 | steps: 70 | - name: Checkout repository 71 | uses: actions/checkout@v4 72 | 73 | - name: Update lycheeVersion in action.yml 74 | uses: mikefarah/yq@master 75 | with: 76 | cmd: yq -i '.inputs.lycheeVersion.default = "${{ env.release_version }}"' action.yml 77 | 78 | - name: Create Pull Request 79 | uses: peter-evans/create-pull-request@v7 80 | with: 81 | branch: ${{ env.update_branch_name }} 82 | title: "Update lycheeVersion to ${{ env.release_version }}" 83 | body: "This PR updates the lycheeVersion to the latest release version ${{ env.release_version }} ." 84 | labels: "automated-pr" 85 | assignees: mre 86 | reviewers: Arteiii,thomas-zahner 87 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test lychee-action 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | workflow_dispatch: 9 | repository_dispatch: 10 | 11 | env: 12 | CUSTOM_OUTPUT_RELATIVE_PATH: lychee/custom_output.md 13 | CUSTOM_OUTPUT_ABSOLUTE_PATH: /tmp/report.md 14 | CUSTOM_OUTPUT_DUMP_PATH: /tmp/dump.md 15 | 16 | jobs: 17 | lychee-action: 18 | runs-on: ubuntu-latest 19 | name: Test the lychee link checker action 20 | steps: 21 | - name: Checkout 22 | uses: actions/checkout@v4 23 | 24 | - name: test defaults 25 | uses: ./ 26 | 27 | - name: test explicit lychee version 28 | uses: ./ 29 | with: 30 | checkbox: false # not supported in v0.15.1 31 | lycheeVersion: v0.15.1 32 | 33 | - name: test nightly lychee version 34 | uses: ./ 35 | with: 36 | lycheeVersion: nightly 37 | 38 | - name: test latest lychee version 39 | uses: ./ 40 | with: 41 | lycheeVersion: latest 42 | 43 | - name: test globs 44 | uses: ./ 45 | with: 46 | args: >- 47 | --exclude-mail 48 | --verbose 49 | --no-progress 50 | './**/*.md' 51 | './**/*.html' 52 | './**/*.rst' 53 | 54 | - name: test --base argument 55 | uses: ./ 56 | with: 57 | args: >- 58 | --base . 59 | --verbose 60 | --no-progress 61 | './**/*.md' 62 | './**/*.html' 63 | './**/*.rst' 64 | 65 | - name: test working directory functionality 66 | uses: ./ 67 | with: 68 | workingDirectory: fixtures/subdir 69 | args: --dump-inputs '*' 70 | output: ${{ github.workspace }}/working_dir_inputs.txt 71 | 72 | - name: test working directory output 73 | run: | 74 | line_count=$(wc -l < ${{ github.workspace }}/working_dir_inputs.txt) 75 | if ! grep -q "test-working-dir.md" ${{ github.workspace }}/working_dir_inputs.txt || [ "$line_count" -ne 2 ]; then 76 | echo "Working directory test failed. Output:" 77 | cat ${{ github.workspace }}/working_dir_inputs.txt 78 | exit 1 79 | fi 80 | 81 | - name: test custom output relative path - creation 82 | uses: ./ 83 | with: 84 | output: "${{ env.CUSTOM_OUTPUT_RELATIVE_PATH }}" 85 | debug: true 86 | 87 | - name: test custom output relative path - validation 88 | run: | 89 | echo "Checking custom output file at ${{ env.CUSTOM_OUTPUT_RELATIVE_PATH }}" 90 | if [ ! -f "${{ env.CUSTOM_OUTPUT_RELATIVE_PATH }}" ]; then 91 | echo "Not found" 92 | exit 1 93 | else 94 | echo "Found. Contents:" 95 | cat "${{ env.CUSTOM_OUTPUT_RELATIVE_PATH }}" 96 | fi 97 | 98 | - name: test custom output absolute path - creation 99 | uses: ./ 100 | with: 101 | output: "${{ env.CUSTOM_OUTPUT_ABSOLUTE_PATH }}" 102 | debug: true 103 | 104 | - name: test custom output absolute path - validation 105 | run: | 106 | echo "Checking custom output file at ${{ env.CUSTOM_OUTPUT_ABSOLUTE_PATH }}" 107 | if [ ! -f "${{ env.CUSTOM_OUTPUT_ABSOLUTE_PATH }}" ]; then 108 | echo "Not found" 109 | exit 1 110 | else 111 | echo "Found. Contents:" 112 | cat "${{ env.CUSTOM_OUTPUT_ABSOLUTE_PATH }}" 113 | fi 114 | 115 | - name: test dump with custom output path - creation 116 | uses: ./ 117 | with: 118 | args: --dump './**/*.md' './**/*.html' './**/*.rst' 119 | output: "${{ env.CUSTOM_OUTPUT_DUMP_PATH }}" 120 | debug: true 121 | 122 | - name: test dump with custom output path - validation 123 | run: | 124 | echo "Checking dump output file at ${{ env.CUSTOM_OUTPUT_DUMP_PATH }}" 125 | if [ ! -f "${{ env.CUSTOM_OUTPUT_DUMP_PATH }}" ]; then 126 | echo "Not found" 127 | exit 1 128 | else 129 | echo "Found. Contents:" 130 | cat "${{ env.CUSTOM_OUTPUT_DUMP_PATH }}" 131 | fi 132 | 133 | - name: test output set in args and action input 134 | id: output_set_in_args_and_action_input 135 | uses: ./ 136 | with: 137 | args: --output foo - 138 | output: bar 139 | continue-on-error: true 140 | 141 | - name: test output set in args and action input should fail - validation 142 | if: steps.output_set_in_args_and_action_input.outcome != 'failure' 143 | run: | 144 | echo "Output set in args and action input should have failed." 145 | exit 1 146 | 147 | - name: test fail - a lychee error should fail the pipeline 148 | id: fail_test 149 | uses: ./ 150 | with: 151 | args: --verbose --no-progress foo.bar 152 | debug: true 153 | continue-on-error: true 154 | 155 | # Explicitly check the exit code of the previous step 156 | # as it's expected to fail 157 | - name: Check fail 158 | if: steps.fail_test.outcome != 'failure' 159 | run: | 160 | echo "Fail should have failed because the URL is invalid." 161 | exit 1 162 | 163 | - name: test disable fail - it's okay if lychee throws an error 164 | uses: ./ 165 | with: 166 | args: --no-progress foo.bar 167 | fail: false 168 | 169 | - name: test failIfEmpty - no links in input should fail the pipeline 170 | id: fail_if_empty_test 171 | uses: ./ 172 | with: 173 | args: --verbose --no-progress fixtures/empty.md 174 | debug: true 175 | continue-on-error: true 176 | 177 | # Explicitly check the exit code of the previous step 178 | # as it's expected to fail 179 | - name: Check failIfEmpty 180 | if: steps.fail_if_empty_test.outcome != 'failure' 181 | run: | 182 | echo "FailIfEmpty should have failed because no links were found." 183 | exit 1 184 | 185 | - name: test disable failIfEmpty - it's okay if no links are found 186 | uses: ./ 187 | with: 188 | args: --no-progress fixtures/empty.md 189 | failIfEmpty: false 190 | 191 | - name: test disable failIfEmpty - a lychee error should still fail the pipeline 192 | id: fail_but_not_failIfEmpty_test 193 | uses: ./ 194 | with: 195 | args: --verbose --no-progress foo.bar 196 | failIfEmpty: false 197 | debug: true 198 | continue-on-error: true 199 | 200 | # Explicitly check the exit code of the previous step 201 | # as it's expected to fail 202 | - name: Check fail when failIfEmpty is disabled 203 | if: steps.fail_but_not_failIfEmpty_test.outcome != 'failure' 204 | run: | 205 | echo "Fail should have failed because the URL is invalid, even though failIfEmpty is disabled." 206 | exit 1 207 | 208 | - name: test disable fail - no links in input should still fail the pipeline 209 | id: failIfEmpty_but_not_fail_test 210 | uses: ./ 211 | with: 212 | args: --verbose --no-progress fixtures/empty.md 213 | fail: false 214 | debug: true 215 | continue-on-error: true 216 | 217 | # Explicitly check the exit code of the previous step 218 | # as it's expected to fail 219 | - name: Check failIfEmpty when fail is disabled 220 | if: steps.failIfEmpty_but_not_fail_test.outcome != 'failure' 221 | run: | 222 | echo "FailIfEmpty should have failed because no links were found, even though fail is disabled." 223 | exit 1 224 | 225 | - name: Install jq 226 | run: sudo apt-get install jq 227 | 228 | - name: test workflow inputs - Markdown 229 | uses: ./ 230 | with: 231 | args: -v fixtures/TEST.md 232 | format: json 233 | output: ${{ github.workspace }}/foo_md.json 234 | 235 | - name: Validate JSON - Markdown 236 | run: | 237 | if ! jq empty ${{ github.workspace }}/foo_md.json; then 238 | echo "Output file does not exist or is not valid JSON" 239 | exit 1 240 | fi 241 | 242 | - name: test workflow inputs - rST 243 | uses: ./ 244 | with: 245 | args: -v fixtures/TEST.rst 246 | format: json 247 | output: ${{ github.workspace }}/foo_rst.json 248 | 249 | - name: Validate JSON - rST 250 | run: | 251 | if ! jq empty ${{ github.workspace }}/foo_rst.json; then 252 | echo "Output file does not exist or is not valid JSON" 253 | exit 1 254 | fi 255 | 256 | - name: directory 257 | uses: ./ 258 | with: 259 | args: --exclude-mail . 260 | 261 | - name: test format override 262 | uses: ./ 263 | with: 264 | args: --format markdown -v fixtures/TEST.md 265 | format: doesnotexist # gets ignored if format set in args 266 | output: ${{ github.workspace }}/foo.txt 267 | 268 | - name: test debug 269 | uses: ./ 270 | with: 271 | debug: true 272 | 273 | - name: test custom GitHub token 274 | uses: ./ 275 | with: 276 | token: ${{ secrets.CUSTOM_TOKEN }} 277 | 278 | - name: Test exit code set in steps-output 279 | id: lychee_exit_code_test 280 | uses: ./ 281 | with: 282 | args: -- inputdoesnotexist 283 | continue-on-error: true 284 | 285 | - name: Check exit code in steps.outputs 286 | run: | 287 | echo "Lychee exit code: ${{ steps.lychee_exit_code_test.outputs.exit_code }}" 288 | if [[ "${{ steps.lychee_exit_code_test.outputs.exit_code }}" == "1" ]]; then 289 | echo "Lychee correctly failed with exit code 1" 290 | else 291 | echo "Unexpected exit code: ${{ steps.lychee_exit_code_test.outputs.exit_code }}" 292 | echo "Expected exit code 1" 293 | exit 1 294 | fi 295 | lychee-action-arm: 296 | runs-on: ubuntu-24.04-arm 297 | name: Basic check for ARM-based runners 298 | steps: 299 | - name: Checkout 300 | uses: actions/checkout@v4 301 | 302 | - name: test defaults 303 | uses: ./ 304 | 305 | - name: test explicit lychee version 306 | uses: ./ 307 | with: 308 | checkbox: false # not supported in v0.15.1 309 | lycheeVersion: v0.15.1 310 | 311 | - name: test nightly lychee version 312 | uses: ./ 313 | with: 314 | lycheeVersion: nightly 315 | -------------------------------------------------------------------------------- /.github/workflows/test_cache.yml: -------------------------------------------------------------------------------- 1 | name: Test cache 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | workflow_dispatch: 9 | repository_dispatch: 10 | 11 | jobs: 12 | lychee-action: 13 | runs-on: ubuntu-latest 14 | continue-on-error: true 15 | name: Test cache 16 | steps: 17 | - name: Restore lychee cache 18 | uses: actions/cache@v4 19 | with: 20 | path: .lycheecache 21 | key: cache-lychee-${{ github.sha }} 22 | restore-keys: cache-lychee- 23 | 24 | - uses: actions/checkout@v4 25 | 26 | - name: Lychee URL checker 27 | uses: lycheeverse/lychee-action@v2 28 | with: 29 | args: >- 30 | --cache 31 | --verbose 32 | --no-progress 33 | './**/*.md' 34 | './**/*.html' 35 | './**/*.rst' 36 | # Fail the action on broken links. 37 | # If the pipeline fails, the cache will _not_ be stored 38 | fail: true 39 | env: 40 | # to be used in case rate limits are surpassed 41 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 42 | -------------------------------------------------------------------------------- /.github/workflows/versioning.yml: -------------------------------------------------------------------------------- 1 | name: Keep major version tags up-to-date 2 | 3 | on: 4 | release: 5 | types: [published, edited] 6 | 7 | jobs: 8 | actions-tagger: 9 | name: Tag GitHub Action 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: Actions-R-Us/actions-tagger@v2 13 | with: 14 | publish_latest_tag: false 15 | prefer_branch_releases: false 16 | -------------------------------------------------------------------------------- /.lycheeignore: -------------------------------------------------------------------------------- 1 | lycheeverse/lychee-action@.* 2 | https://github.com/org/repo 3 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2022 The lychee maintainers 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 The lychee maintainers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lychee link checking action 2 | 3 | [![GitHub Marketplace](https://img.shields.io/badge/Marketplace-lychee-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](https://github.com/marketplace/actions/lychee-broken-link-checker) 4 | [![Check Links](https://github.com/lycheeverse/lychee-action/actions/workflows/links.yml/badge.svg)](https://github.com/lycheeverse/lychee-action/actions/workflows/links.yml) 5 | 6 | Quickly check links in Markdown, HTML, and text files using [lychee]. 7 | 8 | When used in conjunction with [Create Issue From File], issues will be 9 | opened when the action finds link problems (make sure to specify the `issues: write` permission in the [workflow](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#permissions) or the [job](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idpermissions)). 10 | 11 | ## Usage 12 | 13 | Here is a full example of a GitHub workflow file: 14 | 15 | It will check all repository links once per day and create an issue in case of 16 | errors. Save this under `.github/workflows/links.yml`: 17 | 18 | ```yaml 19 | name: Links 20 | 21 | on: 22 | repository_dispatch: 23 | workflow_dispatch: 24 | schedule: 25 | - cron: "00 18 * * *" 26 | 27 | jobs: 28 | linkChecker: 29 | runs-on: ubuntu-latest 30 | permissions: 31 | issues: write # required for peter-evans/create-issue-from-file 32 | steps: 33 | - uses: actions/checkout@v4 34 | 35 | - name: Link Checker 36 | id: lychee 37 | uses: lycheeverse/lychee-action@v2 38 | with: 39 | fail: false 40 | 41 | - name: Create Issue From File 42 | if: steps.lychee.outputs.exit_code != 0 43 | uses: peter-evans/create-issue-from-file@v5 44 | with: 45 | title: Link Checker Report 46 | content-filepath: ./lychee/out.md 47 | labels: report, automated issue 48 | ``` 49 | 50 | ## Passing arguments 51 | 52 | This action uses [lychee] for link checking. 53 | lychee arguments can be passed to the action via the `args` parameter. 54 | 55 | On top of that, the action also supports some additional arguments. 56 | 57 | | Argument | Examples | Description | 58 | | ---------------- | ----------------------- | --------------------------------------------------------------------------------------- | 59 | | args | `--cache`, `--insecure` | See [lychee's documentation][lychee-args] for all arguments and values | 60 | | debug | `false` | Enable debug output in action (set -x). Helpful for troubleshooting | 61 | | fail | `false` | Fail workflow run on error (i.e. when [lychee exit code][lychee-exit] is not 0) | 62 | | failIfEmpty | `false` | Fail entire pipeline if no links were found | 63 | | format | `markdown`, `json` | Summary output format | 64 | | jobSummary | `false` | Write GitHub job summary (on Markdown output only) | 65 | | lycheeVersion | `v0.15.0`, `nightly` | Overwrite the lychee version to be used | 66 | | output | `lychee/results.md` | Summary output file path | 67 | | token | `""` | Custom GitHub token to use for API calls | 68 | | workingDirectory | `.`, `path/to/subdir/` | Custom working directory to run lychee in. This affects where `output.md` gets created. | 69 | 70 | See [action.yml](./action.yml) for a full list of supported arguments and their default values. 71 | 72 | ### Passing arguments 73 | 74 | Here is how to pass the arguments. 75 | 76 | ```yml 77 | - name: Link Checker 78 | uses: lycheeverse/lychee-action@v2 79 | with: 80 | # Check all markdown, html and reStructuredText files in repo (default) 81 | args: --base . --verbose --no-progress './**/*.md' './**/*.html' './**/*.rst' 82 | # Use json as output format (instead of markdown) 83 | format: json 84 | # Use different output file path 85 | output: /tmp/foo.txt 86 | # Use a custom GitHub token, which 87 | token: ${{ secrets.CUSTOM_TOKEN }} 88 | # Don't fail action on broken links 89 | fail: false 90 | # Run lychee in a different directory. 91 | # Note: This changes the lychee output directory as well. 92 | workingDirectory: website/subdir 93 | ``` 94 | 95 | (If you need a token that requires permissions that aren't available in the 96 | default `GITHUB_TOKEN`, you can create a [personal access 97 | token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) 98 | and pass it to the action via the `token` parameter.) 99 | 100 | ## Utilising the cache feature 101 | 102 | In order to mitigate issues regarding rate limiting or to reduce stress on external resources, one can setup lychee's cache similar to this: 103 | 104 | ```yml 105 | - name: Restore lychee cache 106 | uses: actions/cache@v4 107 | with: 108 | path: .lycheecache 109 | key: cache-lychee-${{ github.sha }} 110 | restore-keys: cache-lychee- 111 | 112 | - name: Run lychee 113 | uses: lycheeverse/lychee-action@v2 114 | with: 115 | args: "--base . --cache --max-cache-age 1d ." 116 | ``` 117 | 118 | It will compare and save the cache based on the given key. 119 | So in this setup, as long as a user triggers the CI run from the same commit, it will be the same key. The first run will save the cache, subsequent runs will not update it (because it's the same commit hash). 120 | For restoring the cache, the most recent available one is used (commit hash doesn't matter). 121 | 122 | If you need more control over when caches are restored and saved, you can split the cache step and e.g. ensure to always save the cache (also when the link check step fails): 123 | 124 | ```yml 125 | - name: Restore lychee cache 126 | id: restore-cache 127 | uses: actions/cache/restore@v4 128 | with: 129 | path: .lycheecache 130 | key: cache-lychee-${{ github.sha }} 131 | restore-keys: cache-lychee- 132 | 133 | - name: Run lychee 134 | uses: lycheeverse/lychee-action@v2 135 | with: 136 | args: "--base . --cache --max-cache-age 1d ." 137 | 138 | - name: Save lychee cache 139 | uses: actions/cache/save@v4 140 | if: always() 141 | with: 142 | path: .lycheecache 143 | key: ${{ steps.restore-cache.outputs.cache-primary-key }} 144 | ``` 145 | 146 | ## Excluding links from getting checked 147 | 148 | Add a `.lycheeignore` file to the root of your repository to exclude links from 149 | getting checked. It supports regular expressions. One expression per line. 150 | 151 | You can also put your `.lycheeignore` into a subdirectory if you set that as the `workingDirectory`. 152 | 153 | ## Fancy badge 154 | 155 | Pro tip: You can add a little badge to your repo to show the status of your 156 | links. Just replace `org` with your organisation name and `repo` with the 157 | repository name and put it into your `README.md`: 158 | 159 | ``` 160 | [![Check Links](https://github.com/org/repo/actions/workflows/links.yml/badge.svg)](https://github.com/org/repo/actions/workflows/links.yml) 161 | ``` 162 | 163 | It will look like this: 164 | 165 | [![Check Links](https://github.com/lycheeverse/lychee-action/actions/workflows/links.yml/badge.svg)](https://github.com/lycheeverse/lychee-action/actions/workflows/links.yml) 166 | 167 | ## Troubleshooting and common problems 168 | 169 | See [lychee's Troubleshooting Guide][troubleshooting] for solutions to common 170 | link-checking problems. 171 | 172 | ## Performance 173 | 174 | A full CI run to scan 576 links takes approximately 1 minute for the 175 | [analysis-tools-dev/static-analysis](https://github.com/analysis-tools-dev/static-analysis) 176 | repository. 177 | 178 | ## Security and Updates 179 | 180 | It is recommended to pin lychee-action to a fixed version [for security 181 | reasons][security]. You can use dependabot to automatically keep your GitHub 182 | actions up-to-date. This is a great way to pin lychee-action, while still 183 | receiving updates in the future. It's a relatively easy thing to do. 184 | 185 | Create a file named `.github/dependabot.yml` with the following contents: 186 | 187 | ```yml 188 | version: 2 189 | updates: 190 | - package-ecosystem: "github-actions" 191 | directory: ".github/workflows" 192 | schedule: 193 | interval: "daily" 194 | ``` 195 | 196 | When you add or update the `dependabot.yml` file, this triggers an immediate check for version updates. 197 | Please see [the documentation][dependabot] for all configuration options. 198 | 199 | ### Security tip 200 | 201 | For additional security when relying on automation to update actions you can pin 202 | the action to a SHA-256 rather than the semver version so as to avoid tag 203 | spoofing Dependabot will still be able to automatically update this. 204 | 205 | For example: 206 | 207 | ```yml 208 | - name: Link Checker 209 | uses: lycheeverse/lychee-action@7da8ec1fc4e01b5a12062ac6c589c10a4ce70d67 # for v2.0.0 210 | ``` 211 | 212 | ## Credits 213 | 214 | This action is based on the deprecated [peter-evans/link-checker] and uses 215 | [lychee] (written in Rust) instead of liche (written in Go) for link checking. 216 | 217 | ## License 218 | 219 | lychee is licensed under either of 220 | 221 | - [Apache License, Version 2.0] ([LICENSE-APACHE](./LICENSE-APACHE)) 222 | - [MIT License] ([LICENSE-MIT](./LICENSE-MIT)) 223 | 224 | at your option. 225 | 226 | [lychee]: https://github.com/lycheeverse/lychee 227 | [lychee-args]: https://github.com/lycheeverse/lychee#commandline-parameters 228 | [lychee-exit]: https://github.com/lycheeverse/lychee#exit-codes 229 | [troubleshooting]: https://github.com/lycheeverse/lychee/blob/master/docs/TROUBLESHOOTING.md 230 | [security]: https://francoisbest.com/posts/2020/the-security-of-github-actions 231 | [dependabot]: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 232 | [peter-evans/link-checker]: https://github.com/peter-evans/link-checker 233 | [create issue from file]: https://github.com/peter-evans/create-issue-from-file 234 | [apache license, version 2.0]: https://www.apache.org/licenses/LICENSE-2.0 235 | [mit license]: https://choosealicense.com/licenses/mit 236 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | To report a vulnerability in lychee-action, [open a private vulnerability report](https://github.com/lycheeverse/lychee-action/security/advisories/new) and you can create a patch on a private fork or, after reporting the problem, our maintainers will fix it as soon as possible. 6 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "Lychee Broken Link Checker" 2 | description: "Quickly check links in Markdown, HTML, and text files" 3 | inputs: 4 | args: 5 | description: "Lychee arguments (https://github.com/lycheeverse/lychee#commandline-parameters)" 6 | default: "--verbose --no-progress './**/*.md' './**/*.html' './**/*.rst'" 7 | required: false 8 | debug: 9 | description: "Enable debug output in action (set -x). Helpful for troubleshooting." 10 | default: false 11 | required: false 12 | fail: 13 | description: "Fail entire pipeline on error (i.e. when lychee exit code is not 0)" 14 | default: true 15 | required: false 16 | failIfEmpty: 17 | description: "Fail entire pipeline if no links were found" 18 | default: true 19 | required: false 20 | format: 21 | description: "Summary output format (e.g. json)" 22 | default: "markdown" 23 | required: false 24 | jobSummary: 25 | description: "Write GitHub job summary at the end of the job (written on Markdown output only)" 26 | default: true 27 | required: false 28 | lycheeVersion: 29 | description: "Use custom version of lychee link checker" 30 | default: v0.18.1 31 | required: false 32 | output: 33 | description: "Summary output file path" 34 | default: "lychee/out.md" 35 | required: false 36 | checkbox: 37 | description: "Add Markdown Styled Checkboxes to the output" 38 | default: true 39 | required: false 40 | token: 41 | description: "Your GitHub Access Token, defaults to: {{ github.token }}" 42 | default: ${{ github.token }} 43 | required: false 44 | workingDirectory: 45 | description: "Directory to run lychee in" 46 | default: "." 47 | required: false 48 | outputs: 49 | exit_code: 50 | description: "The exit code returned from Lychee" 51 | value: ${{ steps.run-lychee.outputs.exit_code }} 52 | runs: 53 | using: "composite" 54 | steps: 55 | - name: Set up environment 56 | run: | 57 | echo "$HOME/.local/bin" >> "$GITHUB_PATH" 58 | mkdir -p "$HOME/.local/bin" 59 | shell: bash 60 | - name: Clean up existing lychee binary 61 | run: | 62 | # Remove any existing lychee binary to prevent conflicts 63 | rm -f "$HOME/.local/bin/lychee" 64 | shell: bash 65 | - name: Download and extract lychee in temp directory 66 | id: lychee-setup 67 | run: | 68 | # Create a temporary directory for downloads and extraction 69 | TEMP_DIR="${RUNNER_TEMP}/lychee-download" 70 | mkdir -p "${TEMP_DIR}" 71 | cd "${TEMP_DIR}" 72 | 73 | ARCH=$(uname -m) 74 | # Determine filename and download URL based on version 75 | if [[ "${LYCHEE_VERSION}" =~ ^v0\.0|^v0\.1[0-5]\. ]]; then 76 | FILENAME="lychee-${LYCHEE_VERSION}-${ARCH}-unknown-linux-gnu.tar.gz" 77 | DOWNLOAD_URL="https://github.com/lycheeverse/lychee/releases/download/${LYCHEE_VERSION}/${FILENAME}" 78 | else 79 | FILENAME="lychee-${ARCH}-unknown-linux-gnu.tar.gz" 80 | if [[ "${LYCHEE_VERSION}" == 'nightly' ]]; then 81 | DOWNLOAD_URL="https://github.com/lycheeverse/lychee/releases/download/nightly/${FILENAME}" 82 | elif [[ "${LYCHEE_VERSION}" == 'latest' ]]; then 83 | DOWNLOAD_URL="https://github.com/lycheeverse/lychee/releases/latest/download/${FILENAME}" 84 | else 85 | DOWNLOAD_URL="https://github.com/lycheeverse/lychee/releases/download/lychee-${LYCHEE_VERSION}/${FILENAME}" 86 | fi 87 | fi 88 | 89 | echo "Downloading from: ${DOWNLOAD_URL}" 90 | curl -sfLO "${DOWNLOAD_URL}" 91 | 92 | echo "Extracting ${FILENAME}" 93 | tar -xvzf "${FILENAME}" 94 | 95 | # Output temp directory for use in later steps 96 | echo "temp_dir=${TEMP_DIR}" >> $GITHUB_OUTPUT 97 | env: 98 | LYCHEE_VERSION: ${{ inputs.lycheeVersion }} 99 | shell: bash 100 | - name: Install lychee 101 | run: | 102 | # Install lychee from the temporary directory 103 | install -t "$HOME/.local/bin" -D "${{ steps.lychee-setup.outputs.temp_dir }}/lychee" 104 | shell: bash 105 | - name: Run Lychee 106 | id: run-lychee 107 | working-directory: ${{ inputs.workingDirectory }} 108 | run: ${{ github.action_path }}/entrypoint.sh 109 | env: 110 | # https://github.com/actions/runner/issues/665 111 | INPUT_TOKEN: ${{ inputs.TOKEN }} 112 | INPUT_ARGS: ${{ inputs.ARGS }} 113 | INPUT_DEBUG: ${{ inputs.DEBUG }} 114 | INPUT_FAIL: ${{ inputs.FAIL }} 115 | INPUT_FAILIFEMPTY: ${{ inputs.FAILIFEMPTY }} 116 | INPUT_FORMAT: ${{ inputs.FORMAT }} 117 | INPUT_JOBSUMMARY: ${{ inputs.JOBSUMMARY }} 118 | INPUT_CHECKBOX: ${{ inputs.CHECKBOX }} 119 | INPUT_OUTPUT: ${{ inputs.OUTPUT }} 120 | shell: bash 121 | branding: 122 | icon: "external-link" 123 | color: "purple" 124 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -l 2 | set -uo pipefail 3 | 4 | # We use ‘set +e’ to prevent the script from exiting immediately if lychee fails. 5 | # This ensures that: 6 | # 1. Lychee exit code can be captured and passed to subsequent steps via `$GITHUB_OUTPUT`. 7 | # 2. This step’s outcome (success/failure) can be controlled according to inputs 8 | # by manually calling the ‘exit’ command. 9 | set +e 10 | 11 | # Enable optional debug output 12 | if [ "${INPUT_DEBUG}" = true ]; then 13 | echo "Debug output enabled" 14 | set -x 15 | fi 16 | 17 | LYCHEE_TMP="$(mktemp)" 18 | GITHUB_WORKFLOW_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}?check_suite_focus=true" 19 | 20 | # If custom GitHub token is set, export it as environment variable 21 | if [ -n "${INPUT_TOKEN:-}" ]; then 22 | export GITHUB_TOKEN="${INPUT_TOKEN}" 23 | fi 24 | 25 | ARGS="${INPUT_ARGS}" 26 | FORMAT="" 27 | # Backwards compatibility: 28 | # If `format` occurs in args, ignore the value from `INPUT_FORMAT` 29 | [[ "$ARGS" =~ "--format " ]] || FORMAT="--format ${INPUT_FORMAT}" 30 | 31 | 32 | # If `output` occurs in args and `INPUT_OUTPUT` is set, exit with an error 33 | if [[ "$ARGS" =~ "--output " ]] && [ -n "${INPUT_OUTPUT:-}" ]; then 34 | echo "Error: 'output' is set in args as well as in the action configuration. Please remove one of them." 35 | exit 1 36 | fi 37 | 38 | # If `--mode` occurs in args and `INPUT_CHECKBOX` is set, exit with an error 39 | # Use `--mode` instead of `--mode task` to ensure that the checkbox is not getting overwritten 40 | if [[ "$ARGS" =~ "--mode" ]] && [ -n "${INPUT_CHECKBOX:-}" ]; then 41 | echo "Error: '--mode' is set in args but 'checkbox' is set in the action configuration. Please remove one of them to avoid conflicts." 42 | exit 1 43 | fi 44 | 45 | CHECKBOX="" 46 | if [ "${INPUT_CHECKBOX}" = true ]; then 47 | # Warn if the version is lower than 0.18.1 48 | function version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" != "$1"; } 49 | lychee_version="$(lychee --version | head -n1 | cut -d" " -f2)" 50 | if version_lt "$lychee_version" "0.18.1"; then 51 | echo "WARNING: 'checkbox' is not supported in lychee versions lower than 0.18.1 (current is $lychee_version). Continuing without 'checkbox'." 52 | else 53 | CHECKBOX="--mode task" 54 | fi 55 | fi 56 | 57 | # Execute lychee 58 | eval lychee ${CHECKBOX} ${FORMAT} --output ${LYCHEE_TMP} ${ARGS} 59 | LYCHEE_EXIT_CODE=$? 60 | 61 | # If no links were found and `failIfEmpty` is set to `true` (and it is by default), 62 | # fail with an error later, but leave lychee exit code untouched. 63 | should_fail_because_empty=false 64 | if [ "${INPUT_FAILIFEMPTY}" = "true" ]; then 65 | # This is a somewhat crude way to check the Markdown output of lychee 66 | if grep -E 'Total\s+\|\s+0' "${LYCHEE_TMP}"; then 67 | echo "No links were found. This usually indicates a configuration error." >> "${LYCHEE_TMP}" 68 | echo "If this was expected, set 'failIfEmpty: false' in the args." >> "${LYCHEE_TMP}" 69 | should_fail_because_empty=true 70 | fi 71 | fi 72 | 73 | if [ ! -f "${LYCHEE_TMP}" ]; then 74 | echo "No output. Check pipeline run to see if lychee panicked." > "${LYCHEE_TMP}" 75 | else 76 | # If we have any output, create a report in the designated directory 77 | mkdir -p "$(dirname -- "${INPUT_OUTPUT}")" 78 | cat "${LYCHEE_TMP}" > "${INPUT_OUTPUT}" 79 | 80 | if [ "${INPUT_FORMAT}" == "markdown" ]; then 81 | echo "[Full Github Actions output](${GITHUB_WORKFLOW_URL})" >> "${INPUT_OUTPUT}" 82 | fi 83 | fi 84 | 85 | # Output to console 86 | cat "${LYCHEE_TMP}" 87 | echo 88 | 89 | if [ "${INPUT_FORMAT}" == "markdown" ]; then 90 | if [ "${INPUT_JOBSUMMARY}" = true ]; then 91 | cat "${LYCHEE_TMP}" > "${GITHUB_STEP_SUMMARY}" 92 | fi 93 | fi 94 | 95 | # Pass lychee exit code to subsequent steps 96 | echo "exit_code=$LYCHEE_EXIT_CODE" >> "$GITHUB_OUTPUT" 97 | 98 | # Determine the outcome of this step 99 | # Exiting with a nonzero value will fail the pipeline, but the specific value 100 | # does not matter. (GitHub does not share it with subsequent steps for composite actions.) 101 | if [ "$should_fail_because_empty" = true ] ; then 102 | # If we decided previously to fail because no links were found, fail 103 | exit 1 104 | elif [ "$INPUT_FAIL" = true ] ; then 105 | # If `fail` is set to `true` (and it is by default), propagate lychee exit code 106 | exit ${LYCHEE_EXIT_CODE} 107 | fi 108 | -------------------------------------------------------------------------------- /fixtures/TEST.md: -------------------------------------------------------------------------------- 1 | ![Logo](awesome.png) 2 | 3 | ![Anchors should be ignored](#awesome) 4 | 5 | Normal link, which should work as expected. 6 | [Wikipedia](https://en.wikipedia.org/wiki/Static_program_analysis) 7 | 8 | Just a normal link without any markup around it should work, too. 9 | https://endler.dev 10 | 11 | Test GZIP compression. (See https://github.com/analysis-tools-dev/static-analysis/issues/350) 12 | [LDRA](https://ldra.com) 13 | 14 | Some more complex formatting to test that Markdown parsing works. 15 | [![CC0](https://i.creativecommons.org/p/zero/1.0/88x31.png)](https://creativecommons.org/publicdomain/zero/1.0/) 16 | 17 | Test HTTP and HTTPS for the same site. 18 | http://google.com/ 19 | https://google.com/ 20 | 21 | test@example.com 22 | -------------------------------------------------------------------------------- /fixtures/TEST.rst: -------------------------------------------------------------------------------- 1 | .. figure:: awesome.png 2 | :alt: Logo 3 | 4 | Logo 5 | 6 | .. figure:: #awesome 7 | :alt: Anchors should be ignored 8 | 9 | Anchors should be ignored 10 | 11 | Normal link, which should work as expected. 12 | `Wikipedia `__ 13 | 14 | Just a normal link without any markup around it should work, too. 15 | https://endler.dev 16 | 17 | Test GZIP compression. (See 18 | https://github.com/analysis-tools-dev/static-analysis/issues/350) 19 | `LDRA `__ 20 | 21 | Some more complex formatting to test that Markdown parsing works. |CC0| 22 | 23 | Test HTTP and HTTPS for the same site. http://spinroot.com/cobra/ 24 | https://spinroot.com/cobra/ 25 | 26 | test@example.com 27 | 28 | .. |CC0| image:: https://i.creativecommons.org/p/zero/1.0/88x31.png 29 | :target: https://creativecommons.org/publicdomain/zero/1.0/ 30 | -------------------------------------------------------------------------------- /fixtures/awesome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycheeverse/lychee-action/82202e5e9c2f4ef1a55a3d02563e1cb6041e5332/fixtures/awesome.png -------------------------------------------------------------------------------- /fixtures/empty.md: -------------------------------------------------------------------------------- 1 | This file contains no links. Used for checking `failIfEmpty` flag. -------------------------------------------------------------------------------- /fixtures/subdir/test-working-dir.md: -------------------------------------------------------------------------------- 1 | # Test File with [Link](https://lychee.cli.rs/) 2 | --------------------------------------------------------------------------------