Skip to content

#419 Add GitHub Action to Check for Dead Links in Documentation #1

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

#419 Add GitHub Action to Check for Dead Links in Documentation #1

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
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
pip install sphinx-linkcheck
# Run Sphinx linkcheck to check for broken URLs
- name: Run Sphinx linkcheck
run: |
cd docs
sphinx-build -b linkcheck source _build/linkcheck # link from source docs to be checked
# Display linkcheck results and fail on broken links
- name: Display linkcheck results
run: |
cat _build/linkcheck/output.txt
# Check if the output contains "broken" & list the broken links
if grep -q "broken" _build/linkcheck/output.txt; then
echo "Broken links detected!"
exit 1 # Fail the job if broken links are found
else
echo "No broken links found."
fi