Skip to content

Commit 6392ee8

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

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Check Links In Pull Requests
2+
permissions: {}
3+
4+
on:
5+
pull_request_target:
6+
types: [opened, reopened, synchronize, ready_for_review]
7+
workflow_call:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
check-links:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Clone repository
19+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20+
with:
21+
fetch-depth: 0
22+
ref: ${{github.event.pull_request.head.ref}}
23+
repository: ${{github.event.pull_request.head.repo.full_name}}
24+
25+
- name: Checkout base branch
26+
run: git checkout ${{ github.event.pull_request.base.ref }}
27+
28+
- name: Get list of changed Markdown files
29+
id: changed-files
30+
run: |
31+
git diff --name-only origin/${{ github.event.pull_request.base.ref }}...${{ github.head_ref }} -- '*.md' > changed-files.txt
32+
cat changed-files.txt
33+
if [ -s changed-files.txt ]; then
34+
echo "Changed md files found"
35+
echo "foundFiles=true" >> $GITHUB_ENV
36+
fi
37+
38+
- name: Switch to PR branch
39+
run: git checkout ${{ github.head_ref }}
40+
41+
- name: Check links in changed files
42+
if: env.foundFiles == 'true'
43+
uses: lycheeverse/lychee-action@f796c8b7d468feb9b8c0a46da3fac0af6874d374 # v2.2.0
44+
with:
45+
failIfEmpty: false
46+
args: |
47+
--no-progress
48+
$(cat changed-files.txt | tr '\n' ' ')
49+
50+
- name: Provide helpful failure message
51+
if: failure()
52+
run: |
53+
echo "::error::Link check failed! Please review the broken links reported above."
54+
echo ""
55+
echo "If certain links are valid but fail due to:"
56+
echo "- CAPTCHA challenges"
57+
echo "- IP blocking"
58+
echo "- Authentication requirements"
59+
echo "- Rate limiting"
60+
echo ""
61+
echo "Consider adding them to .lycheeignore to bypass future checks."
62+
echo "Format: Add one URL pattern per line"
63+
exit 1

.github/workflows/pr-verifier.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: Check PR Title
22
permissions: {}
33

44
on:
5+
workflow_dispatch:
6+
schedule:
7+
- cron: "0 0 1 * *"
8+
repository_dispatch:
9+
# run manually
10+
types: [check-link]
511
workflow_call:
612

713
jobs:
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)