Skip to content

Commit a6602f7

Browse files
committed
Add broken link check: general and pr
Signed-off-by: peppi-lotta <[email protected]>
1 parent 804242f commit a6602f7

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

.github/workflows/pr-link-check.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Check Links In Pull Requests
2+
permissions: {}
3+
4+
on:
5+
workflow_call:
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
check-links:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Clone repository
17+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
18+
with:
19+
fetch-depth: 0
20+
ref: ${{github.event.pull_request.head.ref}}
21+
repository: ${{github.event.pull_request.head.repo.full_name}}
22+
23+
- name: Checkout base branch
24+
run: git checkout ${{ github.event.pull_request.base.ref }}
25+
26+
- name: Get list of changed Markdown files
27+
id: changed-files
28+
run: |
29+
git diff --name-only origin/${{ github.event.pull_request.base.ref }}...${{ github.head_ref }} -- '*.md' > changed-files.txt
30+
cat changed-files.txt
31+
if [ -s changed-files.txt ]; then
32+
echo "Changed md files found"
33+
echo "foundFiles=true" >> $GITHUB_ENV
34+
fi
35+
36+
- name: Switch to PR branch
37+
run: git checkout ${{ github.head_ref }}
38+
39+
- name: Check links in changed files
40+
if: env.foundFiles == 'true'
41+
uses: lycheeverse/lychee-action@f796c8b7d468feb9b8c0a46da3fac0af6874d374 # v2.2.0
42+
with:
43+
failIfEmpty: false
44+
args: |
45+
--no-progress
46+
$(cat changed-files.txt | tr '\n' ' ')
47+
48+
- name: Provide helpful failure message
49+
if: failure()
50+
run: |
51+
echo "::error::Link check failed! Please review the broken links reported above."
52+
echo ""
53+
echo "If certain links are valid but fail due to:"
54+
echo "- CAPTCHA challenges"
55+
echo "- IP blocking"
56+
echo "- Authentication requirements"
57+
echo "- Rate limiting"
58+
echo ""
59+
echo "Consider adding them to .lycheeignore to bypass future checks."
60+
echo "Format: Add one URL pattern per line"
61+
exit 1
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Check Links
2+
on:
3+
workflow_call
4+
5+
permissions: {}
6+
7+
jobs:
8+
check:
9+
runs-on: ubuntu-latest
10+
11+
permissions:
12+
contents: read
13+
issues: write
14+
15+
steps:
16+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17+
18+
- name: Link Checker
19+
id: linkcheck
20+
uses: lycheeverse/lychee-action@f796c8b7d468feb9b8c0a46da3fac0af6874d374 # v2.2.0
21+
with:
22+
args: |
23+
--user-agent "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0"
24+
--root-dir "$(pwd)/"
25+
--fallback-extensions "md"
26+
"./**/*.md"
27+
output: /tmp/lychee_output.md
28+
fail: false
29+
30+
- name: Create Issue From File
31+
if: steps.linkcheck.outputs.exit_code != 0
32+
uses: peter-evans/create-issue-from-file@e8ef132d6df98ed982188e460ebb3b5d4ef3a9cd # v5.0.1
33+
with:
34+
title: Link Checker Report
35+
content-filepath: /tmp/lychee_output.md
36+
labels: |
37+
kind/bug

0 commit comments

Comments
 (0)