Skip to content

Commit a725c9c

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

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
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

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
32+
- name: Switch to PR branch
33+
run: git checkout ${{ github.head_ref }}
34+
35+
- name: Check links in changed files
36+
uses: lycheeverse/lychee-action@f796c8b7d468feb9b8c0a46da3fac0af6874d374 # v2.2.0
37+
with:
38+
failIfEmpty: false
39+
args: |
40+
--no-progress
41+
$(cat changed-files.txt | tr '\n' ' ')
42+
43+
- name: Provide helpful failure message
44+
if: failure()
45+
run: |
46+
echo "::error::Link check failed! Please review the broken links reported above."
47+
echo ""
48+
echo "If certain links are valid but fail due to:"
49+
echo "- CAPTCHA challenges"
50+
echo "- IP blocking"
51+
echo "- Authentication requirements"
52+
echo "- Rate limiting"
53+
echo ""
54+
echo "Consider adding them to .lycheeignore to bypass future checks."
55+
echo "Format: Add one URL pattern per line"
56+
exit 1

0 commit comments

Comments
 (0)