Skip to content

Commit a873494

Browse files
authored
Create link_checkPR.yml
1 parent 31eb1da commit a873494

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

.github/workflows/link_checkPR.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: link check on PR
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
check-links:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Clone repository
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
ref: ${{github.event.pull_request.head.ref}}
16+
repository: ${{github.event.pull_request.head.repo.full_name}}
17+
18+
- name: Check out main branch
19+
run: git checkout main
20+
21+
- name: Dump all links from main
22+
id: dump_links_from_main
23+
uses: lycheeverse/lychee-action@v1
24+
with:
25+
args: |
26+
--dump
27+
--include-fragments
28+
.
29+
output: ./links-main.txt
30+
31+
- name: Stash untracked files
32+
run: git stash push --include-untracked
33+
34+
- name: Check out feature branch
35+
run: git checkout ${{ github.head_ref }}
36+
37+
- name: Apply stashed changes
38+
# Apply stashed changes, ignore errors if stash is empty
39+
run: git stash pop || true
40+
41+
- name: Append links-main.txt to .lycheeignore
42+
run: cat links-main.txt >> .lycheeignore
43+
44+
- name: Check links
45+
uses: lycheeverse/lychee-action@v1
46+
with:
47+
args: |
48+
--no-progress
49+
--include-fragments
50+
.
51+
# Fail action on broken links
52+
fail: true
53+
54+
- name: Suggestions
55+
if: failure()
56+
run: |
57+
echo -e "\nPlease review the links reported in the Check links step above."
58+
echo -e "If a link is valid but fails due to a CAPTCHA challenge, IP blocking, login requirements, etc.,
59+
consider adding such links to .lycheeignore file to bypass future checks.\n"
60+
exit 1

0 commit comments

Comments
 (0)