55 branches :
66 - main
77 paths :
8- - ' **/*.md' # Only trigger workflow if any Markdown files change
8+ - ' **/*.md'
99
1010jobs :
1111 check-links :
1212 runs-on : ubuntu-latest
1313 steps :
14- # Step 1: Checkout the repository
15- - name : Checkout GitHub repo
16- uses : actions/checkout@v4
14+ # Checkout repo
15+ - uses : actions/checkout@v4
1716 with :
1817 fetch-depth : 0
1918
20- # Step 2: Check out base branch
21- - name : Check out base branch
22- run : git checkout ${{ github.event.pull_request.base.ref }}
23-
24- # Step 3: Get changed Markdown files
19+ # Find changed Markdown files
2520 - name : Get changed Markdown files
2621 id : changed-files
2722 run : |
@@ -30,39 +25,14 @@ jobs:
3025 echo "Changed Markdown files:"
3126 echo "$files"
3227
33- # Step 4: Skip workflow if no Markdown files changed
28+ # Skip if no Markdown files
3429 - name : Skip if no Markdown files changed
3530 if : ${{ env.changed_files == '' }}
3631 run : |
37- echo "No Markdown files changed in this PR . Skipping link check."
32+ echo "No Markdown files changed. Skipping link check."
3833 exit 0
3934
40- # Step 5: Dump base branch links for changed files only (no fragments)
41- - name : Dump base branch links
42- uses : lycheeverse/lychee-action@v2
43- with :
44- args : " --dump ${{ env.changed_files }}"
45- output : ./existing-links.txt
46- continue-on-error : true
47-
48- # Step 6: Stash untracked files and switch back to feature branch
49- - name : Stash untracked files
50- run : git stash push --include-untracked
51-
52- - name : Check out feature branch
53- run : git checkout ${{ github.head_ref }}
54-
55- - name : Apply stashed changes
56- run : git stash pop || true
57-
58- # Step 7: Add base branch links to .lycheeignore
59- - name : Update ignore file
60- run : |
61- if [ -f "existing-links.txt" ]; then
62- cat existing-links.txt >> .lycheeignore
63- fi
64-
65- # Step 8: Run Lychee on changed files one by one and extract broken links
35+ # Run Lychee
6636 - name : Run Lychee link checker
6737 id : lychee
6838 continue-on-error : true
@@ -73,33 +43,17 @@ jobs:
7343 lychee --no-progress --include-fragments "$f" >> lychee-full-report.txt || true
7444 done
7545
76- # Extract only broken links
77- if [ -f lychee-full-report.txt ]; then
78- grep -E "❌|ERROR" lychee-full-report.txt > lychee-broken.txt || true
46+ # Extract only broken links for log
47+ if grep -qE "❌|ERROR" lychee-full-report.txt; then
48+ echo "❌ Broken links found:"
49+ grep -E "❌|ERROR" lychee-full-report.txt
7950 else
80- echo "No report generated." > lychee-broken.txt
51+ echo "✅ No broken links found."
8152 fi
8253
83- echo "full_report=lychee-full-report.txt" >> $GITHUB_ENV
84- echo "broken_report=lychee-broken.txt" >> $GITHUB_ENV
85-
86- # Step 9: Upload full report for debugging (optional)
87- - name : Upload full Lychee report
54+ # Upload full report as artifact
55+ - name : Upload Lychee full report
8856 uses : actions/upload-artifact@v4
8957 with :
9058 name : lychee-full-report
91- path : ${{ env.full_report }}
92-
93- # Step 10: Post PR comment with only broken links
94- - name : Comment broken links on PR
95- if : always()
96- uses : marocchino/sticky-pull-request-comment@v2
97- with :
98- path : ${{ env.broken_report }}
99-
100- # Step 11: Fail if broken links exist
101- - name : Fail on broken links
102- if : steps.lychee.outcome == 'failure'
103- run : |
104- echo "::error::Broken links detected. See the PR comment above for details."
105- exit 1
59+ path : lychee-full-report.txt
0 commit comments