Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/check_external_links.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Check external links

# Checks every external link in the docs on PRs that change the docs. A broken
# link shows up as a warning and never fails the PR, because an external site
# can break a link that the PR didn't touch.

on:
pull_request:
paths:
- "docs/**"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
contents: read

jobs:
check-external-links:
name: External links (warnings only, not caused by this PR)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1

- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97
with:
python-version: '3.10'

- name: Install doc-builder
run: |
pip install git+https://github.com/huggingface/doc-builder.git@main

- name: Check external links
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
status=0
doc-builder check-links docs/source/en --check-external --format list > link-report.txt || status=$?
cat link-report.txt

# Turn each broken external link into a warning on its file and line.
broken=0
while IFS= read -r line; do
file=${line%%:*}
rest=${line#*:}
message=${rest#* - }
message=${message//%/%25}
echo "::warning file=$file,line=${rest%% - *},title=Broken external link::$message"
broken=$((broken + 1))
done < <(sed '/Could not verify/q' link-report.txt | grep -E '^[^ ]+:[0-9]+ - https?://' || true)

{
echo '## External link check'
echo '```'
cat link-report.txt
echo '```'
} >> "$GITHUB_STEP_SUMMARY"

if [ "$status" -ne 0 ] && [ "$broken" -eq 0 ]; then
echo "::error::check-links failed without listing a broken external link. See the log above."
exit 1
fi