Skip to content

Commit

Permalink
Add broken link checker GitHub workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
szh committed Feb 10, 2023
1 parent 44b045e commit 923df37
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/md-broken-link-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Credit to https://github.com/OWASP/CheatSheetSeries
name: Markdown Broken Link Check

on:
push:
pull_request:
branches:
- main

jobs:
link-check:
runs-on: ubuntu-22.04
env:
CI: true
steps:
- name: Setup Action
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 12.x
- name: Install dependencies
run: npm install
- name: Run link check
run: npm run link-check
- name: Show broken links
if: failure()
run: |
cat log | awk -v RS="FILE:" 'match($0, /(\S*\.md).*\[✖\].*(\d*\slinks\schecked\.)(.*)/, arr ) { print "FILE:"arr[1] arr[3] > "brokenlinks"}'
rm -f err log
cat brokenlinks
links=`cat brokenlinks`
links="${links//'%'/'%25'}"
links="${links//$'\n'/'%0A'}"
links="${links//$'\r'/'%0D'}"
echo ::set-output name=links::**Following links are broken:** %0A$links
- name: Send comment to PR with broken links
if: failure() && github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@main
with:
message: ${{ steps.brokenlinks.outputs.links }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
_site/
node_modules/
package-lock.json
/log
/err
33 changes: 33 additions & 0 deletions markdown-link-check-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"ignorePatterns": [
{
"pattern": "^bundle.zip"
},
{
"pattern": "^News.xml"
},
{
"pattern": "^/"
},
{
"pattern": "vincent.bernat.im"
},
{
"pattern": "developer.android.com"
},
{
"pattern": "csrc.nist.gov"
},
{
"pattern": "www.exploit-db.com"
}
],
"httpHeaders": [
{
"urls": ["https://", "http://"],
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0"
}
}
]
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
"textlint": "^12.5.1",
"textlint-filter-rule-comments": "^1.2.2",
"textlint-filter-rule-allowlist": "^4.0.0",
"textlint-rule-terminology": "^3.0.4"
"textlint-rule-terminology": "^3.0.4",
"markdown-link-check": "^3.10.3"
},
"scripts": {
"test": "npm run lint-markdown && npm run lint-terminology",
"lint-terminology": "textlint ./2022",
"lint-markdown": "markdownlint ./2022"
"lint-markdown": "markdownlint ./2022",
"link-check": "find 2022 -name \\*.md -exec markdown-link-check -c markdown-link-check-config.json 1> log 2> err {} \\; && if [ -e err ] && grep -q \"ERROR:\" err ; then exit 113 ; else echo -e \"All good\"; fi"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 923df37

Please sign in to comment.