88
99permissions :
1010 contents : read
11-
11+
1212concurrency :
1313 group : ${{ github.workflow }}-${{ github.ref }}
1414 cancel-in-progress : true
@@ -18,52 +18,54 @@ jobs:
1818 runs-on : ubuntu-latest
1919
2020 steps :
21- - name : Checkout PR branch
21+ - name : Clone repository
2222 uses : actions/checkout@v4
2323 with :
2424 fetch-depth : 0
25+ ref : ${{github.event.pull_request.head.ref}}
26+ repository : ${{github.event.pull_request.head.repo.full_name}}
2527
26- - name : Set up Git
27- run : git fetch origin ${{ github.base_ref }}
28+ - name : Check out base branch
29+ run : git checkout ${{github.event.pull_request.base.ref }}
2830
29- - name : Get added/modified Markdown files
30- id : changed-files
31- run : |
32- files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '\.md$' || true)
33- echo "md_files<<EOF" >> $GITHUB_OUTPUT
34- echo "$files" >> $GITHUB_OUTPUT
35- echo "EOF" >> $GITHUB_OUTPUT
31+ - name : Dump all links from ${{github.event.pull_request.base.ref}}
32+ uses : lycheeverse/lychee-action@v2
33+ with :
34+ args : |
35+ --dump
36+ --include-fragments
37+ --verbose --exclude-mail --no-progress --exclude ^https?://
38+ .
39+ output : ./existing-links.txt
40+ continue-on-error : true # Don't fail if base branch check has issues
3641
37- - name : Dump base branch links into ignore file
38- if : steps.changed-files.outputs.md_files != ''
39- run : |
40- git checkout origin/${{ github.base_ref }}
41- mkdir -p .lychee
42- lychee --dump --include-fragments ${{ steps.changed-files.outputs.md_files }} > .lychee/ignore.txt || true
42+ - name : Stash untracked files
43+ run : git stash push --include-untracked
4344
44- - name : Checkout PR branch again
45+ - name : Check out feature branch
4546 run : git checkout ${{ github.head_ref }}
4647
47- - name : Run lychee on PR changes
48- if : steps.changed-files.outputs.md_files != ''
49- uses :
lycheeverse/[email protected] 48+ - name : Apply stashed changes
49+ run : git stash pop || true
50+
51+ - name : Update ignore file
52+ run : |
53+ if [ -f "existing-links.txt" ]; then
54+ cat existing-links.txt >> .lycheeignore
55+ fi
56+
57+ - name : Check links
58+ uses : lycheeverse/lychee-action@v2
5059 with :
5160 args : >
52- --no-progress --include-fragments
53- --max-concurrency 4
54- --exclude-mail
55- -- --ignore-file .lychee/ignore.txt
56- ${{ steps.changed-files.outputs.md_files }}
57- failIfEmpty : false
58- env :
59- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
61+ --verbose --exclude-mail --no-progress --exclude ^https?://
62+ .
6063
61- - name : Provide helpful message on failure
64+ - name : Provide helpful failure message
6265 if : failure()
6366 run : |
64- echo "::error::Link check failed! Please review broken links above."
65- echo "If some links are false positives (e.g. behind auth, CAPTCHA),"
66- echo "you can add them to a .lycheeignore or adjust the check."
67+ echo "::error::Link check failed! Please review the broken links reported above."
68+ echo "Format: Add one URL pattern per line"
6769 exit 1
6870
6971 - name : Check Broken Links in Entire Repo (Manual)
0 commit comments