1- name : Check Links
1+ name : Check Links In Pull Requests
22
33on :
44 pull_request :
5- types : [opened, synchronize, reopened]
5+ branches :
6+ - main
7+ paths :
8+ - ' **/*.md' # Only trigger workflow if any Markdown files change
69
710jobs :
811 check-links :
912 runs-on : ubuntu-latest
1013 steps :
11- - uses : actions/checkout@v4
12- - uses : lycheeverse/lychee-action@v2
13- - name : Comment Broken Links
14- uses : marocchino/sticky-pull-request-comment@v2
14+ # Step 1: Checkout the repository
15+ - name : Checkout GitHub repo
16+ uses : actions/checkout@v4
1517 with :
16- path : lychee/out.md
18+ fetch-depth : 0
19+
20+ # Step 2: Check out base branch and dump all links (no fragments)
21+ - name : Check out base branch
22+ run : git checkout ${{ github.event.pull_request.base.ref }}
23+
24+ - name : Dump all links from base branch (no fragments)
25+ uses : lycheeverse/lychee-action@v2
26+ with :
27+ args : " --dump ."
28+ output : ./existing-links.txt
29+ continue-on-error : true
30+
31+ # Step 3: Stash untracked files and switch back to feature branch
32+ - name : Stash untracked files
33+ run : git stash push --include-untracked
34+
35+ - name : Check out feature branch
36+ run : git checkout ${{ github.head_ref }}
37+
38+ - name : Apply stashed changes
39+ run : git stash pop || true
40+
41+ # Step 4: Add base branch links to .lycheeignore
42+ - name : Update ignore file
43+ run : |
44+ if [ -f "existing-links.txt" ]; then
45+ cat existing-links.txt >> .lycheeignore
46+ fi
47+
48+ # Step 5: Get changed Markdown files in the PR
49+ - name : Get changed Markdown files
50+ id : changed-files
51+ run : |
52+ files=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }} ${{ github.head_ref }} | grep '\.md$' || true)
53+ echo "changed_files=$files" >> $GITHUB_ENV
54+
55+ # Step 6: Run Lychee on changed files only (with fragments)
56+ - name : Run Lychee link checker
57+ uses : lycheeverse/lychee-action@v2
58+ with :
59+ args : " --no-progress --include-fragments ${{ env.changed_files }}"
60+
61+ # Step 7: Provide a helpful failure message
62+ - name : Helpful failure message
63+ if : ${{ failure() }}
64+ run : |
65+ echo "::error::Link check failed! Please review the broken links reported above."
66+ echo ""
67+ echo "If certain links are valid but fail due to:"
68+ echo "- CAPTCHA challenges"
69+ echo "- IP blocking"
70+ echo "- Authentication requirements"
71+ echo "- Rate limiting"
72+ echo ""
73+ echo "Consider adding them to .lycheeignore to bypass future checks."
74+ echo "Format: Add one URL pattern per line"
75+ exit 1
0 commit comments