Broken Link Checker #22
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: | |
| jobs: | |
| markdown-link-check: | |
| name: Check Markdown Broken Links | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # === PR MODE === | |
| - name: Get Changed Markdown Files (PR) | |
| id: changed-files | |
| 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: Run Lychee on Changed Files (PR) | |
| if: github.event_name == 'pull_request' && steps.changed-files.outputs.md_files != '' | |
| uses: lycheeverse/[email protected] | |
| with: | |
| args: > | |
| --verbose --no-progress --exclude-mail | |
| --exclude ^https?:// | |
| --output lychee/pr.out | |
| ${{ steps.changed-files.outputs.md_files }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Affected Markdown Files (PR) | |
| if: github.event_name == 'pull_request' | |
| id: affected-pr | |
| run: | | |
| mkdir -p sanitized_md | |
| affected=$(grep -Eo 'file://[^ ]+\.md' lychee/pr.out | sed 's|file://||' | sort -u) | |
| echo "$affected" | |
| echo "affected_files<<EOF" >> $GITHUB_OUTPUT | |
| echo "$affected" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Strip HTML Comments from Affected Files (PR) | |
| if: steps.affected-pr.outputs.affected_files != '' | |
| run: | | |
| echo "${{ steps.affected-pr.outputs.affected_files }}" | while read file; do | |
| if [ -f "$file" ]; then | |
| target="sanitized_md/$file" | |
| mkdir -p "$(dirname "$target")" | |
| perl -0777 -pe 's/<!--.*?-->//gs' "$file" > "$target" | |
| fi | |
| done | |
| - name: Re-check Sanitized Affected Files (PR) | |
| if: steps.affected-pr.outputs.affected_files != '' | |
| uses: lycheeverse/[email protected] | |
| with: | |
| args: > | |
| --verbose --no-progress --exclude-mail | |
| --exclude ^https?:// | |
| sanitized_md/**/*.md | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # === MANUAL MODE === | |
| - name: Run Lychee on Entire Repo (Manual) | |
| if: github.event_name == 'workflow_dispatch' | |
| uses: lycheeverse/[email protected] | |
| with: | |
| args: > | |
| --verbose --no-progress --exclude-mail | |
| --exclude ^https?:// | |
| --output lychee/manual.out | |
| '**/*.md' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Affected Markdown Files (Manual) | |
| if: github.event_name == 'workflow_dispatch' | |
| id: affected-manual | |
| run: | | |
| mkdir -p sanitized_md | |
| affected=$(grep -Eo 'file://[^ ]+\.md' lychee/manual.out | sed 's|file://||' | sort -u) | |
| echo "$affected" | |
| echo "affected_files<<EOF" >> $GITHUB_OUTPUT | |
| echo "$affected" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Strip HTML Comments from Affected Files (Manual) | |
| if: steps.affected-manual.outputs.affected_files != '' | |
| run: | | |
| echo "${{ steps.affected-manual.outputs.affected_files }}" | while read file; do | |
| if [ -f "$file" ]; then | |
| target="sanitized_md/$file" | |
| mkdir -p "$(dirname "$target")" | |
| perl -0777 -pe 's/<!--.*?-->//gs' "$file" > "$target" | |
| fi | |
| done | |
| - name: Re-run Lychee on Sanitized Affected Files (Manual) | |
| if: steps.affected-manual.outputs.affected_files != '' | |
| uses: lycheeverse/[email protected] | |
| with: | |
| args: > | |
| --verbose --no-progress --exclude-mail | |
| --exclude ^https?:// | |
| --output lychee/manual-cleaned.out | |
| sanitized_md/**/*.md | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |