Skip to content

Commit 9ba7b58

Browse files
Update Broken-links-checker-final.yml
1 parent 1578a32 commit 9ba7b58

File tree

1 file changed

+19
-47
lines changed

1 file changed

+19
-47
lines changed

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

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

33
on:
44
pull_request:
@@ -9,65 +9,37 @@ on:
99
permissions:
1010
contents: read
1111

12-
concurrency:
13-
group: ${{ github.workflow }}-${{ github.ref }}
14-
cancel-in-progress: true
15-
1612
jobs:
17-
check-links:
13+
markdown-link-check:
14+
name: Check Markdown Broken Links
1815
runs-on: ubuntu-latest
1916

2017
steps:
21-
- name: Clone repository
18+
- name: Checkout Repo
2219
uses: actions/checkout@v4
2320
with:
2421
fetch-depth: 0
25-
ref: ${{github.event.pull_request.head.ref}}
26-
repository: ${{github.event.pull_request.head.repo.full_name}}
27-
28-
- name: Check out base branch
29-
run: git checkout ${{github.event.pull_request.base.ref}}
30-
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
41-
42-
- name: Stash untracked files
43-
run: git stash push --include-untracked
44-
45-
- name: Check out feature branch
46-
run: git checkout ${{ github.head_ref }}
4722

48-
- name: Apply stashed changes
49-
run: git stash pop || true
50-
51-
- name: Update ignore file
23+
- name: Get Added/Modified Markdown Files (PR only)
24+
id: changed-files
25+
if: github.event_name == 'pull_request'
5226
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
27+
git fetch origin ${{ github.base_ref }}
28+
files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '\.md$' || true)
29+
echo "md_files<<EOF" >> $GITHUB_OUTPUT
30+
echo "$files" >> $GITHUB_OUTPUT
31+
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 != ''
34+
uses: lycheeverse/[email protected]
5935
with:
6036
args: >
6137
--verbose --exclude-mail --no-progress --exclude ^https?://
62-
.
38+
${{ steps.changed-files.outputs.md_files }}
39+
failIfEmpty: false
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6342

64-
- name: Provide helpful failure message
65-
if: failure()
66-
run: |
67-
echo "::error::Link check failed! Please review the broken links reported above."
68-
echo "Format: Add one URL pattern per line"
69-
exit 1
70-
7143
- name: Check Broken Links in Entire Repo (Manual)
7244
if: github.event_name == 'workflow_dispatch'
7345
uses: lycheeverse/[email protected]

0 commit comments

Comments
 (0)