-
Notifications
You must be signed in to change notification settings - Fork 100
64 lines (52 loc) · 1.95 KB
/
test-external-links.yml
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
name: Test external links
on:
# Ideally this would be a scheduled action to catch if a website *did* work, but subsequently went offline
# But then it would have to notify *someone*, whereas a PR author notification is easier
pull_request:
jobs:
test-external-links:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install Lynx
run: |
sudo apt-get update
sudo apt-get install -y lynx
- name: Build documentation
run: |
npm i
npm run-script build-local
- run: |
echo "temp_file=$(mktemp)" >> $GITHUB_ENV
- name: Extract links
run: |
# Extract all unique URLs
# Faster than potentially checking the same link on multiple pages
find . -name "*.html" | while read -r file; do
lynx -dump -listonly -nonumbers "${file}" | { grep -E "^http" || test $? = 1; } >> "${temp_file}"
done
- name: Check links
run: |
distinct_urls=$(sort -u "${temp_file}")
while read -r url; do
if [[ -n "${url}" ]]; then
echo "::debug::Checking URL '${url}'..."
status=$(curl --globoff --no-progress-meter --output /dev/null --location --head --write-out "%{http_code}" "${url}" || true)
if [[ "${status}" -eq 404 ]]; then
locations=$(grep -rl "${url}")
echo "::error::❌ URL '${url}' had status ${status} (found in ${locations})" 1>&2
found_error=1
else
echo "::debug::✅ URL '${url}' had status ${status}"
fi
fi
done <<< "${distinct_urls}"
if [[ "${found_error}" -eq 1 ]]; then
exit 1
else
exit 0
fi