-
Notifications
You must be signed in to change notification settings - Fork 64
78 lines (61 loc) · 2.27 KB
/
Copy pathlink-checker-pr.yml
File metadata and controls
78 lines (61 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Link Checker for Pull requests
on: pull_request
jobs:
changedFiles:
runs-on: ubuntu-latest
outputs:
files: ${{ steps.changed-markdown-files.outputs.all_changed_files }}
steps:
- uses: actions/checkout@v4
- name: Get changed markdown files
id: changed-markdown-files
uses: tj-actions/changed-files@v46
with:
files: |
**/*.md
matrix: true
linkChecker:
runs-on: ubuntu-latest
needs: changedFiles
if: ${{ needs.changedFiles.outputs.files != '' && toJSON(fromJSON(needs.changedFiles.outputs.files)) != '[]' }}
strategy:
matrix:
file: ${{ fromJSON(needs.changedFiles.outputs.files) }}
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Download Lychee
run: |
wget https://github.com/lycheeverse/lychee/releases/download/lychee-v0.19.1/lychee-x86_64-unknown-linux-gnu.tar.gz
tar xzf lychee-x86_64-unknown-linux-gnu.tar.gz
- name: Check added lines in file for broken links
run: |
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
echo "Checking links in changed lines of: ${{ matrix.file }}"
# Extract raw added lines from diff
DIFF=$(git diff -U0 "$BASE_SHA" "$HEAD_SHA" -- ${{ matrix.file }} | \
grep -v "+++" | grep "^+" | cut -c 2-)
if [ -z "$DIFF" ]; then
echo "No added lines at all. Skipping."
exit 0
fi
# Extract only actual URLs from added lines
LINK_LINES=$(echo "$DIFF" | grep -Eo '(https?://[^ )\]}]+|www\.[^ )\]}]+)' || true)
if [ -z "$LINK_LINES" ]; then
echo "Added lines contain no URLs. Skipping link checking."
exit 0
fi
echo "Running Lychee on extracted links:"
echo "$LINK_LINES"
echo "$LINK_LINES" | \
./lychee \
--fallback-extensions=md \
--exclude-all-private \
--exclude support.posit.co \
--exclude www.intel.com \
--exclude reddit.com \
--exclude jsfiddle.net \
--exclude 'file://'