Skip to content

Commit 3cc8b44

Browse files
Check newly added links in PRs
1 parent ecf32d9 commit 3cc8b44

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,39 @@ jobs:
5454
run: |
5555
python -m pip install --upgrade nox virtualenv
5656
57+
- name: Restore linkcheck baseline
58+
if: matrix.noxenv == 'linkcheck' && github.event_name == 'pull_request'
59+
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
60+
with:
61+
path: .linkcheck-baseline/output.json
62+
key: linkcheck-output-${{ github.event.pull_request.base.sha }}
63+
restore-keys: |
64+
linkcheck-output-
65+
5766
- name: Nox ${{ matrix.noxenv }}
5867
env:
5968
# Authenticate github.com requests during linkcheck to avoid rate limits.
6069
GITHUB_TOKEN: ${{ matrix.noxenv == 'linkcheck' && github.token || '' }}
70+
# Ignore links that were already reported by the baseline linkcheck run.
71+
LINKCHECK_IGNORE_FILE: >-
72+
${{ matrix.noxenv == 'linkcheck' && '.linkcheck-baseline/output.json' || '' }}
6173
run: |
6274
python -m nox -s ${{ matrix.noxenv }}
6375
76+
- name: Prepare linkcheck baseline
77+
if: matrix.noxenv == 'linkcheck' && github.event_name == 'push' && github.ref == 'refs/heads/main'
78+
run: |
79+
mkdir -p .linkcheck-baseline
80+
cp build/output.json .linkcheck-baseline/output.json
81+
82+
- name: Save linkcheck baseline
83+
if: matrix.noxenv == 'linkcheck' && github.event_name == 'push' && github.ref == 'refs/heads/main'
84+
continue-on-error: true
85+
uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
86+
with:
87+
path: .linkcheck-baseline/output.json
88+
key: linkcheck-output-${{ github.sha }}
89+
6490

6591
check:
6692
# This job does nothing and is only used for the branch protection

‎source/conf.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# -- Project information ---------------------------------------------------------------
22
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
33

4+
import json
45
import os
56
import pathlib
7+
import re
68
import sys
79

810
_ROOT = pathlib.Path(__file__).resolve().parent.parent
@@ -163,6 +165,20 @@
163165
# Temporarily ignored due to expired TLS cert.
164166
r"https://kivy.org/.*",
165167
]
168+
169+
if _linkcheck_ignore_file := os.getenv("LINKCHECK_IGNORE_FILE"):
170+
linkcheck_ignore_path = pathlib.Path(_linkcheck_ignore_file)
171+
if linkcheck_ignore_path.is_file():
172+
with linkcheck_ignore_path.open(encoding="utf-8") as linkcheck_ignore_file:
173+
for line in linkcheck_ignore_file:
174+
try:
175+
linkcheck_entry = json.loads(line)
176+
except json.JSONDecodeError:
177+
continue
178+
179+
if linkcheck_uri := linkcheck_entry.get("uri"):
180+
linkcheck_ignore.append(rf"^{re.escape(linkcheck_uri)}$")
181+
166182
linkcheck_retries = 2
167183
linkcheck_timeout = 30
168184
# Ignore anchors for common targets when we know they likely won't be found

0 commit comments

Comments
 (0)