Skip to content

Add GitHub Action to Check for Dead Links in Documentation #12

Add GitHub Action to Check for Dead Links in Documentation

Add GitHub Action to Check for Dead Links in Documentation #12

name: Link Checker for Sphinx Documentation
# Trigger the workflow on push to main branch or pull request to main branch
on:
push:
branches: [main]
pull_request:
branches: [main]
types: [opened, reopened, synchronize]
jobs:
link-check:
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout repository
uses: actions/checkout@v3
# Set up Python
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: '3.x'
# Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r docs/requirements.txt #installing the required packages from repo docs/requirements.txt
echo "Dependencies installed."
# Run Sphinx linkcheck to check for broken URLs
- name: Run Sphinx linkcheck
run: |
cd docs
sphinx-build -b linkcheck source _build/linkcheck || true # link from source docs to be checked
grep "broken" _build/linkcheck/output.txt > broken_links.txt #output of broken links to broken_links.txt from _builds/linkcheck/output.txt
if [ -s broken_links.txt ]; then
echo "Broken links found:"
cat broken_links.txt
else
echo "No broken links found."
fi