Skip to content

Commit 6377abb

Browse files
ci: check newly added links
1 parent bdc08be commit 6377abb

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,45 @@ jobs:
5454
run: |
5555
python -m pip install --upgrade nox virtualenv
5656
57+
- name: Restore linkcheck baseline
58+
if: >-
59+
${{ matrix.noxenv == 'linkcheck' &&
60+
(github.event_name == 'pull_request' || github.event_name == 'merge_group') }}
61+
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
62+
with:
63+
path: build/linkcheck-baseline.json
64+
key: linkcheck-${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
65+
restore-keys: |
66+
linkcheck-
67+
5768
- name: Nox ${{ matrix.noxenv }}
5869
env:
5970
# Authenticate github.com requests during linkcheck to avoid rate limits.
6071
GITHUB_TOKEN: ${{ matrix.noxenv == 'linkcheck' && github.token || '' }}
72+
LINKCHECK_BASELINE: >-
73+
${{ matrix.noxenv == 'linkcheck' &&
74+
(github.event_name == 'pull_request' || github.event_name == 'merge_group') &&
75+
'build/linkcheck-baseline.json' || '' }}
6176
run: |
6277
python -m nox -s ${{ matrix.noxenv }}
6378
79+
- name: Prepare linkcheck baseline
80+
if: >-
81+
${{ always() && matrix.noxenv == 'linkcheck' &&
82+
github.event_name == 'push' && github.ref == 'refs/heads/main' &&
83+
hashFiles('build/output.json') != '' }}
84+
run: cp build/output.json build/linkcheck-baseline.json
85+
86+
- name: Save linkcheck baseline
87+
if: >-
88+
${{ always() && matrix.noxenv == 'linkcheck' &&
89+
github.event_name == 'push' && github.ref == 'refs/heads/main' &&
90+
hashFiles('build/linkcheck-baseline.json') != '' }}
91+
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
92+
with:
93+
path: build/linkcheck-baseline.json
94+
key: linkcheck-${{ github.sha }}
95+
6496

6597
check:
6698
# This job does nothing and is only used for the branch protection

‎source/conf.py‎

Lines changed: 14 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
@@ -165,6 +167,18 @@
165167
# Temporarily ignored due to expired TLS cert.
166168
r"https://kivy.org/.*",
167169
]
170+
171+
if _linkcheck_baseline := os.getenv("LINKCHECK_BASELINE"):
172+
_baseline_path = pathlib.Path(_linkcheck_baseline)
173+
if _baseline_path.is_file():
174+
for _record in _baseline_path.read_text(encoding="utf-8").splitlines():
175+
try:
176+
_uri = json.loads(_record).get("uri")
177+
except json.JSONDecodeError:
178+
continue
179+
if _uri:
180+
linkcheck_ignore.append(rf"^{re.escape(_uri)}$")
181+
168182
linkcheck_retries = 2
169183
linkcheck_timeout = 30
170184
# Ignore anchors for common targets when we know they likely won't be found

0 commit comments

Comments
 (0)