Skip to content

Commit 52a1ad8

Browse files
Update Broken-links-checker-final.yml
1 parent 661102f commit 52a1ad8

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

.github/workflows/Broken-links-checker-final.yml

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Broken Link Checker
1+
name: Check Links In Pull Requests
22

33
on:
44
pull_request:
@@ -8,44 +8,71 @@ on:
88

99
permissions:
1010
contents: read
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
1115

1216
jobs:
13-
markdown-link-check:
14-
name: Check Markdown Broken Links
17+
check-links:
1518
runs-on: ubuntu-latest
1619

1720
steps:
18-
- name: Checkout Repo
21+
- name: Checkout PR branch
1922
uses: actions/checkout@v4
2023
with:
2124
fetch-depth: 0
2225

23-
- name: Get Added/Modified Markdown Files (PR only)
26+
- name: Set up Git
27+
run: git fetch origin ${{ github.base_ref }}
28+
29+
- name: Get added/modified Markdown files
2430
id: changed-files
25-
if: github.event_name == 'pull_request'
2631
run: |
27-
git fetch origin ${{ github.base_ref }}
2832
files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '\.md$' || true)
2933
echo "md_files<<EOF" >> $GITHUB_OUTPUT
3034
echo "$files" >> $GITHUB_OUTPUT
3135
echo "EOF" >> $GITHUB_OUTPUT
32-
- name: Check Broken Links in Added/Modified Files (PR)
33-
if: github.event_name == 'pull_request' && steps.changed-files.outputs.md_files != ''
36+
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
43+
44+
- name: Checkout PR branch again
45+
run: git checkout ${{ github.head_ref }}
46+
47+
- name: Run lychee on PR changes
48+
if: steps.changed-files.outputs.md_files != ''
3449
uses: lycheeverse/[email protected]
3550
with:
3651
args: >
37-
--verbose --exclude-mail --no-progress --exclude ^https?://
52+
--no-progress --include-fragments
53+
--max-concurrency 4
54+
--exclude-mail
55+
--accept 200,429
56+
--ignore-file .lychee/ignore.txt
3857
${{ steps.changed-files.outputs.md_files }}
3958
failIfEmpty: false
4059
env:
4160
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4261

62+
- name: Provide helpful message on failure
63+
if: failure()
64+
run: |
65+
echo "::error::Link check failed! Please review broken links above."
66+
echo "If some links are false positives (e.g. behind auth, CAPTCHA),"
67+
echo "you can add them to a .lycheeignore or adjust the check."
68+
exit 1
69+
4370
- name: Check Broken Links in Entire Repo (Manual)
4471
if: github.event_name == 'workflow_dispatch'
4572
uses: lycheeverse/[email protected]
4673
with:
4774
args: >
48-
--verbose --exclude-mail --no-progress --exclude ^https?://
75+
--verbose --exclude-mail --no-progress --exclude ^https?://
4976
'**/*.md'
5077
failIfEmpty: false
5178
output: lychee/out.md

0 commit comments

Comments
 (0)