Skip to content

Check Links

Check Links #5

Workflow file for this run

name: Check Links
on:
# Run monday mornings
schedule:
- cron: '0 12 * * MON'
workflow_dispatch:
jobs:
check-links:
name: Check links
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
site:
- name: Fern Docs
url: "buildwithfern.com/learn"
steps:
- name: Install link checker
run: pip install linkchecker
- name: Create config
run: echo -e "[csv]\nseparator=,\n[filtering]\nignore=\n\texample.com\n\tus.i.posthog.com\n\tdocs.stack-auth.com\n\tc.vialoops.com/CL0\n[output]\nignoreerrors=\n ^http ^403 Forbidden" > lcconfig
- name: Check ${{ matrix.site.name }} Links
run: |
set +e
cat lcconfig
linkchecker https://${{ matrix.site.url }} --check-extern --no-status --no-warnings --config lcconfig -F csv/utf-8/link_report.csv
if [ $? -ne 0 ]; then
echo "Bad links found. Please see report."
else
echo "Check completed. No issues found."
exit 0
fi
echo "Scan done, generating summary"
started=false
shouldfail=false
while read p; do
# skip comments (top and bottom)
if [[ $p == \#* ]]; then
continue
fi
# make sure first line after comments is skipped
if [[ "$started" = false ]]; then
started=true
continue
fi
IFS=',' read -r -a array <<< "$p"
ret=$(curl -I -s "${array[0]}" -o /dev/null -w "%{http_code}\n")
if [[ $ret == 200 ]]; then
echo "Site now seems to be working, we should continue here"
continue
else
echo "There is still an issue with ${array[0]}"
fi
shouldfail=true
if [[ ${array[10]} == '' ]]; then
echo "::error::URL: ${array[0]} on page: ${array[1]} is returning a ${array[3]}"
else
echo "::error::URL: ${array[0]} linked from '${array[10]}' on page: ${array[1]} is returning a ${array[3]}"
fi
done < link_report.csv
if [[ "$shouldfail" = false ]]; then
exit 0
fi
exit 1
- name: Upload report
if: failure()
uses: actions/upload-artifact@v4
with:
name: Report - ${{ matrix.site.name }}
path: link_report.csv