Broken Link Checker #26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Broken Link Checker | |
| on: | |
| pull_request: | |
| paths: | |
| - '**/*.md' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| markdown-link-check: | |
| name: Check Markdown Broken Links | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repo | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get Added/Modified Markdown Files | |
| id: changed | |
| if: github.event_name == 'pull_request' | |
| run: | | |
| git fetch origin ${{ github.base_ref }} | |
| files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '\.md$' || true) | |
| echo "md_files<<EOF" >> $GITHUB_OUTPUT | |
| echo "$files" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Strip HTML comments from Markdown | |
| if: github.event_name == 'pull_request' && steps.changed.outputs.md_files != '' | |
| run: | | |
| for file in ${{ steps.changed.outputs.md_files }}; do | |
| awk -v FS="" ' | |
| BEGIN { in_comment = 0 } | |
| { | |
| if (in_comment) { | |
| if (match($0, /-->/)) { | |
| $0 = substr($0, RSTART + RLENGTH) | |
| in_comment = 0 | |
| } else { next } | |
| } | |
| while (match($0, /<!--/)) { | |
| prefix = substr($0, 1, RSTART - 1) | |
| rest = substr($0, RSTART + 4) | |
| if (match(rest, /-->/)) { | |
| rest = substr(rest, RSTART + RLENGTH) | |
| $0 = prefix rest | |
| } else { | |
| $0 = prefix | |
| in_comment = 1 | |
| break | |
| } | |
| } | |
| } | |
| ' "$file" > tmp && mv tmp "$file" | |
| done | |
| - name: Check Broken Links in Added/Modified Files | |
| if: github.event_name == 'pull_request' && steps.changed.outputs.md_files != '' | |
| uses: lycheeverse/[email protected] | |
| with: | |
| args: > | |
| --verbose --exclude-mail --no-progress --exclude ^https?:// | |
| ${{ steps.changed.outputs.md_files }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Strip HTML comments (manual run) | |
| if: github.event_name == 'workflow_dispatch' | |
| run: | | |
| for file in **/*.md; do | |
| awk -v FS="" ' | |
| BEGIN { in_comment = 0 } | |
| { | |
| if (in_comment) { | |
| if (match($0, /-->/)) { | |
| $0 = substr($0, RSTART + RLENGTH) | |
| in_comment = 0 | |
| } else { next } | |
| } | |
| while (match($0, /<!--/)) { | |
| prefix = substr($0, 1, RSTART - 1) | |
| rest = substr($0, RSTART + 4) | |
| if (match(rest, /-->/)) { | |
| rest = substr(rest, RSTART + RLENGTH) | |
| $0 = prefix rest | |
| } else { | |
| $0 = prefix | |
| in_comment = 1 | |
| break | |
| } | |
| } | |
| } | |
| ' "$file" > tmp && mv tmp "$file" | |
| done | |
| - name: Check Broken Links in Entire Repo | |
| if: github.event_name == 'workflow_dispatch' | |
| uses: lycheeverse/[email protected] | |
| with: | |
| args: > | |
| --verbose --exclude-mail --no-progress --exclude ^https?:// | |
| '**/*.md' | |
| output: lychee/out.md | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |