Skip to content

Broken Link Checker #49

Broken Link Checker

Broken Link Checker #49

name: Check Links In Pull Requests
on:
pull_request:
paths:
- '**/*.md'
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-links:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Check out base branch
run: git checkout ${{github.event.pull_request.base.ref}}
- name: Dump all links from ${{github.event.pull_request.base.ref}}
uses: lycheeverse/lychee-action@v2
with:
args: |
--dump
--include-fragments
--verbose --exclude-mail --no-progress --exclude ^https?://
.
output: ./existing-links.txt
continue-on-error: true # Don't fail if base branch check has issues
- name: Stash untracked files
run: git stash push --include-untracked
- name: Check out feature branch
run: git checkout ${{ github.head_ref }}
- name: Apply stashed changes
run: git stash pop || true
- name: Update ignore file
run: |
if [ -f "existing-links.txt" ]; then
cat existing-links.txt >> .lycheeignore
fi
- name: Check links
uses: lycheeverse/lychee-action@v2
with:
args: >
--verbose --exclude-mail --no-progress --exclude ^https?://
.
- name: Provide helpful failure message
if: failure()
run: |
echo "::error::Link check failed! Please review the broken links reported above."
echo "Format: Add one URL pattern per line"
exit 1
- name: Check Broken Links in Entire Repo (Manual)
if: github.event_name == 'workflow_dispatch'
uses: lycheeverse/[email protected]
with:
args: >
--verbose --exclude-mail --no-progress --exclude ^https?://
'**/*.md'
failIfEmpty: false
output: lychee/out.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}