@@ -17,18 +17,38 @@ jobs:
1717 with :
1818 fetch-depth : 0
1919
20- # Step 2: Check out base branch and dump all links (no fragments)
20+ # Step 2: Check out base branch
2121 - name : Check out base branch
2222 run : git checkout ${{ github.event.pull_request.base.ref }}
2323
24- - name : Dump all links from base branch (no fragments)
24+ # Step 3: Get changed Markdown files
25+ - name : Get changed Markdown files
26+ id : changed-files
27+ run : |
28+ mapfile -t files_array < <(git diff --name-only origin/${{ github.event.pull_request.base.ref }} ${{ github.head_ref }} | grep '\.md$' || true)
29+ files=""
30+ for f in "${files_array[@]}"; do
31+ files="$files \"$f\""
32+ done
33+ echo "changed_files=$files" >> $GITHUB_ENV
34+ echo "Changed Markdown files: $files"
35+
36+ # Step 4: Skip workflow if no Markdown files changed
37+ - name : Skip if no Markdown files changed
38+ if : ${{ env.changed_files == '' }}
39+ run : |
40+ echo "No Markdown files changed in this PR. Skipping link check."
41+ exit 0
42+
43+ # Step 5: Dump base branch links for changed files only (no fragments)
44+ - name : Dump base branch links
2545 uses : lycheeverse/lychee-action@v2
2646 with :
27- args : " --dump . "
47+ args : " --dump ${{ env.changed_files }} "
2848 output : ./existing-links.txt
2949 continue-on-error : true
3050
31- # Step 3 : Stash untracked files and switch back to feature branch
51+ # Step 6 : Stash untracked files and switch back to feature branch
3252 - name : Stash untracked files
3353 run : git stash push --include-untracked
3454
@@ -38,29 +58,22 @@ jobs:
3858 - name : Apply stashed changes
3959 run : git stash pop || true
4060
41- # Step 4 : Add base branch links to .lycheeignore
61+ # Step 7 : Add base branch links to .lycheeignore
4262 - name : Update ignore file
4363 run : |
4464 if [ -f "existing-links.txt" ]; then
4565 cat existing-links.txt >> .lycheeignore
4666 fi
4767
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- files=$(echo "$files" | tr '\n' ' ')
54- echo "changed_files=$files" >> $GITHUB_ENV
55-
56- # Step 6: Run Lychee on changed files only (with fragments)
68+ # Step 8: Run Lychee on changed files one by one
5769 - name : Run Lychee link checker
58- if : ${{ env.changed_files != '' }}
59- uses : lycheeverse/lychee-action@v2
60- with :
61- args : " --no-progress --include-fragments ${{ env.changed_files }}"
70+ run : |
71+ for f in ${{ env.changed_files }}; do
72+ echo "Checking links in $f"
73+ lychee --no-progress --include-fragments "$f"
74+ done
6275
63- # Step 7 : Provide a helpful failure message
76+ # Step 9 : Provide a helpful failure message
6477 - name : Helpful failure message
6578 if : ${{ failure() }}
6679 run : |
0 commit comments