Skip to content

Commit 27327bb

Browse files
add link-checking CI
moving over from the fern repo. Planning to schedule for weekly runs and send alerts to myself to resolve issues.
1 parent 0296a99 commit 27327bb

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

.github/workflows/check-links.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Check Links
2+
3+
on:
4+
# TODO: Enable scheduled scanning once standing issues have been resolved
5+
#schedule:
6+
#- cron: "0 0 * * *"
7+
workflow_dispatch:
8+
jobs:
9+
check-links:
10+
name: Check links
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
site:
16+
- name: Fern Docs
17+
url: "buildwithfern.com/learn"
18+
steps:
19+
- name: Install link checker
20+
run: pip install linkchecker
21+
- name: Create config
22+
run: echo -e "[csv]\nseparator=,\n[filtering]\nignore=\n\texample.com\n\tus.i.posthog.com\n\tc.vialoops.com/CL0\n[output]\nignoreerrors=\n ^http ^403 Forbidden" > lcconfig
23+
- name: Check ${{ matrix.site.name }} Links
24+
run: |
25+
set +e
26+
cat lcconfig
27+
linkchecker https://${{ matrix.site.url }} --check-extern --no-status --no-warnings --config lcconfig -F csv/utf-8/link_report.csv
28+
29+
if [ $? -ne 0 ]; then
30+
echo "Bad links found. Please see report."
31+
else
32+
echo "Check completed. No issues found."
33+
exit 0
34+
fi
35+
36+
echo "Scan done, generating summary"
37+
38+
started=false
39+
shouldfail=false
40+
while read p; do
41+
# skip comments (top and bottom)
42+
if [[ $p == \#* ]]; then
43+
continue
44+
fi
45+
# make sure first line after comments is skipped
46+
if [[ "$started" = false ]]; then
47+
started=true
48+
continue
49+
fi
50+
51+
IFS=',' read -r -a array <<< "$p"
52+
53+
ret=$(curl -I -s "${array[0]}" -o /dev/null -w "%{http_code}\n")
54+
if [[ $ret == 200 ]]; then
55+
echo "Site now seems to be working, we should continue here"
56+
continue
57+
else
58+
echo "There is still an issue with ${array[0]}"
59+
fi
60+
61+
shouldfail=true
62+
63+
if [[ ${array[10]} == '' ]]; then
64+
echo "::error::URL: ${array[0]} on page: ${array[1]} is returning a ${array[3]}"
65+
else
66+
echo "::error::URL: ${array[0]} linked from '${array[10]}' on page: ${array[1]} is returning a ${array[3]}"
67+
fi
68+
69+
done < link_report.csv
70+
71+
if [[ "$shouldfail" = false ]]; then
72+
exit 0
73+
fi
74+
75+
exit 1
76+
77+
- name: Upload report
78+
if: failure()
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: Report - ${{ matrix.site.name }}
82+
path: link_report.csv

0 commit comments

Comments
 (0)