├── Dockerfile ├── .github └── workflows │ └── main.yml ├── action.yml ├── LICENCE ├── README.md └── entrypoint.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.10 2 | RUN apk add --no-cache bash nodejs npm jq 3 | ADD entrypoint.sh /entrypoint.sh 4 | RUN chmod +x /entrypoint.sh 5 | ENTRYPOINT ["/entrypoint.sh"] 6 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Broken link check 2 | on: [push] 3 | 4 | jobs: 5 | broken_link_checker_job: 6 | runs-on: ubuntu-latest 7 | name: Check for broken links 8 | steps: 9 | - name: Check for broken links 10 | id: link-report 11 | uses: celinekurpershoek/link-checker@master 12 | with: 13 | url: "https://github.com/celinekurpershoek/link-checker" 14 | honorRobotExclusions: true 15 | ignorePatterns: "github" 16 | recursiveLinks: false 17 | - name: Get the result 18 | run: echo "${{steps.link-report.outputs.result}}" 19 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'broken-link-check' 2 | description: 'Find broken links, missing images, etc within your HTML.' 3 | author: 'Celine Kurpershoek' 4 | branding: 5 | icon: 'anchor' 6 | color: 'purple' 7 | inputs: 8 | url: # id of input 9 | description: 'Url of site' 10 | required: true 11 | default: 'https://github.com/celinekurpershoek/link-checker' 12 | honorRobotExclusions: 13 | description: 'Overwrite standard skipping rel=nofollow links' 14 | required: false 15 | default: true 16 | ignorePatterns: 17 | description: 'Ignore urls based on patterns' 18 | required: false 19 | default: '' 20 | recursiveLinks: 21 | description: 'Walk through the whole website and check all the urls' 22 | required: false 23 | default: false 24 | outputs: 25 | result: # id of output 26 | description: 'Report of links' 27 | runs: 28 | using: 'docker' 29 | image: 'Dockerfile' 30 | args: 31 | - ${{ inputs.url }} 32 | - ${{ inputs.honorRobotExclusions }} 33 | - ${{ inputs.ignorePatterns }} 34 | - ${{ inputs.recursiveLinks }} 35 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Celine Kurpershoek 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Broken link check action 2 | 3 | This action uses: https://github.com/stevenvachon/broken-link-checker 4 | 5 | Find broken links in your website. 6 | 7 | ## How to use 8 | 9 | Create a new file in your repository .github/workflows/action.yml. 10 | 11 | Copy-paste the following workflow in your action.yml file: 12 | 13 | ```yml 14 | name: Broken link check 15 | on: [push] 16 | 17 | jobs: 18 | broken_link_checker_job: 19 | runs-on: ubuntu-latest 20 | name: Check for broken links 21 | steps: 22 | - name: Check for broken links 23 | id: link-report 24 | uses: celinekurpershoek/link-checker@v1.0.2 25 | with: 26 | # Required: 27 | url: "https://..." 28 | # optional: 29 | honorRobotExclusions: false 30 | ignorePatterns: "github,google" 31 | recursiveLinks: false # Check all URLs on all reachable pages (could take a while) 32 | - name: Get the result 33 | run: echo "${{steps.link-report.outputs.result}}" 34 | ``` 35 | 36 | ## Optional parameters: 37 | 38 | ### `honorRobotExclusions` 39 | 40 | Type: `Boolean` 41 | Default value: `true` 42 | The script does not scan pages that search engine crawlers would not follow. 43 | https://github.com/stevenvachon/broken-link-checker#honorrobotexclusions 44 | 45 | ### `ignorePatterns` 46 | 47 | type: `String` 48 | Default value: `''` 49 | A comma-separated string of matched URLs to ignore. Check documentation about patterns here: https://github.com/stevenvachon/broken-link-checker#excludedkeywords 50 | 51 | ### `recursiveLinks` 52 | 53 | type: `Boolean` 54 | Default value: `false` 55 | A boolean to do a site-wide check, it will add the `blc` `-ro` param to the command 56 | 57 | ## todo: 58 | 59 | - [ ] Create issue if broken URLs are found 60 | - [ ] Parse each broken link in report on new line 61 | 62 | ## Test 63 | 64 | There is a broken link in this document as a test: 65 | [A broken link](http://jhgfdsadfghjklkjhgfdsasdfgh.com) 66 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Fail when any task exits with a non-zero error 3 | set -e 4 | 5 | NC='\033[0m' # No Color 6 | RED='\033[0;31m' 7 | GREEN='\033[0;32m' 8 | YELLOW='\033[0;33m' 9 | PURPLE='\033[0;34m' 10 | 11 | # Install the broken-link-checker module globally on the docker instance 12 | npm i -g broken-link-checker -s 13 | 14 | echo -e "$PURPLE=== BROKEN LINK CHECKER ===$NC" 15 | echo -e "Running broken link checker on URL: $GREEN $1 $NC" 16 | 17 | # Create exclude and settings strings based on configuration 18 | EXCLUDE="" 19 | SET_FOLLOW="" 20 | SET_RECURSIVE="" 21 | 22 | if [ -z "$1" ] || [ "$1" == 'https://github.com/celinekurpershoek/link-checker' ] 23 | then 24 | echo -e "$YELLOW Warning: Running test on default URL, please provide a URL in your action.yml.$NC" 25 | fi 26 | 27 | # Set arguments for blc 28 | [ "$2" == false ] && SET_FOLLOW="--follow" 29 | 30 | [ "$4" == true ] && SET_RECURSIVE="-ro" 31 | 32 | for PATTERN in ${3//,/ }; do 33 | EXCLUDE+="--exclude $PATTERN " 34 | done 35 | 36 | # Echo settings if any are set 37 | echo -e "Configuration: \n Honor robot exclusions: $GREEN$2$NC, \n Exclude URLs that match: $GREEN$3$NC, \n Resursive URLs: $GREEN$4$NC" 38 | 39 | # Create command and remove extra quotes 40 | # Put result in variable to be able to iterate on it later 41 | OUTPUT="$(blc "$1" $EXCLUDE $SET_FOLLOW $SET_RECURSIVE -v | sed 's/"//g')" 42 | 43 | # Count lines of output 44 | TOTAL_COUNT="$(wc -l <<< "$OUTPUT")" 45 | 46 | # Count 'BROKEN' lines of result or return 0 47 | if grep -q 'BROKEN' <<< "$OUTPUT" 48 | then 49 | BROKEN="$(grep -q 'BROKEN' <<< "$OUTPUT")" 50 | BROKEN_COUNT="$(wc -l <<< "$BROKEN")" 51 | else 52 | BROKEN_COUNT=0 53 | fi 54 | 55 | # Return results 56 | if [ "$BROKEN_COUNT" -gt 0 ] 57 | then 58 | RESULT="$BROKEN_COUNT broken link(s) found (out of $TOTAL_COUNT total)" 59 | echo -e "$RED Failed $RESULT: $NC" 60 | grep -E 'BROKEN' <<< "$OUTPUT" | awk '{print "[✗] " $2 "\n" }' 61 | echo -e "$PURPLE ============================== $NC" 62 | echo "result=$RESULT" >> "$GITHUB_OUTPUT" 63 | exit 1 64 | elif [ "$TOTAL_COUNT" == 0 ] 65 | then 66 | echo -e "Didn't find any links to check" 67 | else 68 | RESULT="✓ Checked $TOTAL_COUNT link(s), no broken links found!" 69 | echo -e "$GREEN $RESULT $NC" 70 | echo "result=$RESULT" >> "$GITHUB_OUTPUT" 71 | echo -e "$PURPLE ============================== $NC" 72 | fi 73 | exit 0 74 | --------------------------------------------------------------------------------