From 9fb5601d9bdf145f509e031348a5c2682fd830d6 Mon Sep 17 00:00:00 2001 From: julianz- <6255571+julianz-@users.noreply.github.com> Date: Fri, 2 Oct 2026 18:32:01 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Unignore=20GitHub=20links=20in?= =?UTF-8?q?=20Sphinx's=20linkcheck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sphinx gained proper HTTP 429 rate-limit handling (backing off and retrying) years after a blanket github.com exclusion was added to work around it, leaving hundreds of commit/issue/pull-request/file links in the changelog and history unchecked ever since. Removed that exclusion and verified a full linkcheck run passes cleanly without it. Also authenticated those requests with GITHUB_TOKEN, raising the rate limit from 60/hour (anonymous) to 5000/hour. An earlier attempt to wire this up via `secrets.GITHUB_TOKEN` in a reusable workflow's `with:` input was invalid (the `secrets` context isn't accessible there) and broke the whole workflow trigger; `github.token` works instead, since the `github` context is accessible in that position. Inspired by pypa/packaging.python.org#2032, which solved the same problem. --- .github/workflows/ci-cd.yml | 10 ++++++++ docs/changelog-fragments.d/851.contrib.rst | 13 ++++++++++ docs/conf.py | 29 ++++++++++++---------- 3 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 docs/changelog-fragments.d/851.contrib.rst diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 6287e68db8..84e1316185 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -649,6 +649,16 @@ jobs: }} dists-artifact-name: >- ${{ needs.pre-setup.outputs.dists-artifact-name }} + # NOTE: Raises linkcheck's GitHub request rate limit from 60/hour + # NOTE: (anonymous) to 5000/hour (authenticated). See `docs/conf.py`. + # NOTE: `github.token` (not `secrets.GITHUB_TOKEN`) because the + # NOTE: `secrets` context isn't accessible in a `with:` input. + environment-variables: >- + ${{ + matrix.toxenv == 'linkcheck-docs' + && format('GITHUB_TOKEN={0}', github.token) + || '' + }} post-toxenv-preparation-command: >- ${{ matrix.toxenv == 'pre-commit' diff --git a/docs/changelog-fragments.d/851.contrib.rst b/docs/changelog-fragments.d/851.contrib.rst new file mode 100644 index 0000000000..a87711ee7b --- /dev/null +++ b/docs/changelog-fragments.d/851.contrib.rst @@ -0,0 +1,13 @@ +Removed the long-standing blanket +:external+sphinx:confval:`linkcheck_ignore` exclusion of +`github.com `_ commit/issue/pull-request/file +links: that workaround +predated Sphinx gaining proper rate-limit handling (backing off and +retrying on HTTP 429), so it was silently leaving hundreds of GitHub +links in the changelog and history unchecked. Also authenticated +those requests via +:external+sphinx:confval:`linkcheck_request_headers`, using the +``GITHUB_TOKEN`` CI already provisions for every workflow run, to +raise the anonymous 60-per-hour rate limit to 5000 per hour. + +-- by :user:`julianz-` diff --git a/docs/conf.py b/docs/conf.py index 89292604d8..d041fc17e4 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -102,19 +102,6 @@ r'http://localhost:\d+/', # local URLs r'https://codecov\.io/gh/cherrypy/cheroot/branch/master/graph/badge\.svg', r'https://github\.com/cherrypy/cheroot/actions', # 404 if no auth - # Too many links to GitHub so they cause - # "429 Client Error: too many requests for url" - # Ref: https://github.com/sphinx-doc/sphinx/issues/7388 - r'https://github\.com/cherrypy/cheroot/blob', - r'https://github\.com/cherrypy/cheroot/commit', - r'https://github\.com/cherrypy/cheroot/issues', - r'https://github\.com/cherrypy/cheroot/pull', - r'https://github\.com/cherrypy/cheroot/tree', - r'https://github\.com/cherrypy/cherrypy/blob', - r'https://github\.com/cherrypy/cherrypy/commit', - r'https://github\.com/cherrypy/cherrypy/issues', - r'https://github\.com/cherrypy/cherrypy/pull', - r'https://github\.com/cherrypy/cherrypy/tree', # Has an ephemeral anchor (line-range) but actual HTML has separate per- # line anchors. ( @@ -131,6 +118,22 @@ r'^https://forums\.sabnzbd\.org/', # these generate HTTP 403 Forbidden r'^https://web\.archive\.org/web/', # these timeout ] +linkcheck_request_headers = ( + { + 'https://github.com/': { + 'Authorization': f'Bearer {os.environ["GITHUB_TOKEN"]}', + }, + 'https://api.github.com/': { + 'Authorization': f'Bearer {os.environ["GITHUB_TOKEN"]}', + }, + } + if os.environ.get('GITHUB_TOKEN') + # Anonymous GitHub requests are capped at 60/hour; an authenticated + # token raises that to 5000/hour, keeping `linkcheck` from needing + # to back off and retry when checking the many GitHub links in the + # changelog/history. + else {} +) linkcheck_anchors_ignore = [ r'^!', # default # ignore anchors that start with a '/', e.g. Wikipedia media files: