Skip to content

[doc][ci] Skip RTD builds for PRs that don't touch doc sources - #63431

Merged
elliot-barn merged 2 commits into
ray-project:masterfrom
dstrodtman:djs-260518-rtd-skip-non-doc-builds
Jun 3, 2026
Merged

elliot-barn merged 2 commits into
ray-project:masterfrom
dstrodtman:djs-260518-rtd-skip-non-doc-builds

Conversation

@dstrodtman

Copy link
Copy Markdown
Contributor

Description

Adds a build.jobs.post_checkout block to .readthedocs.yaml that exits with code 183 on PR ("external") builds when the diff doesn't touch any files that affect documentation output. Tag and branch builds (master, stable, etc.) always run.

Why

Today, every PR to ray-project/ray triggers a full Sphinx build on Read the Docs, regardless of what the PR touches. A PR that only changes C++, Java, Bazel, release tooling, or CI config produces the same docs build as a PR that rewrites doc/.

When several PRs land in quick succession, this overflows the project's concurrent build slots on RTD. RTD's finish_inactive_builds periodic task then marks the older queued builds as FAILED with the message "This build was terminated due to inactivity" (see readthedocs.org#4386 — the name is misleading; the build isn't inactive, it just couldn't get a worker within ~1080 seconds). Contributors then see red checks on their PRs that have nothing to do with their changes.

Auto-cancellation of older builds for the same PR has been on by default in RTD since October 2022, but that only helps when you push twice to one PR — not across multiple open PRs. This change complements that by reducing the load from cross-PR concurrency.

What the filter does

On every PR build, it computes the diff against origin/master and exits 183 — RTD's skip-build sentinel — only when none of the changed files match:

  • doc/ — Sphinx sources, BUILD files, doc-only requirements.
  • python/ray/ — anything autodoc could pull (kept intentionally broad).
  • rllib/ — same.
  • .readthedocs.yaml — this config itself, so changes to it always test.

If even one file falls in the allow-list, the build runs as before. If the diff can't be computed (shallow clone, fetch failure), the build runs.

What this skips in practice

PRs that don't touch any of the four paths above. Concrete examples:

  • C++ / Cython changes under src/, cpp/.
  • Java changes under java/.
  • Bazel changes under bazel/, top-level BUILD.bazel, WORKSPACE.
  • CI changes under ci/, .buildkite/ (except .buildkite/doc.rayci.yml which isn't read by Sphinx but is excluded from the allow-list since it doesn't change RTD output).
  • Release tooling under release/.
  • Docker changes under docker/.
  • Top-level scripts and configs.

What still triggers a build

  • All content under doc/.
  • Any python/ray/** change, because autodoc could pick it up.
  • Any rllib/** change, same reason.
  • The RTD config itself.

The filter is deliberately conservative — broad inclusion, narrow exclusion. Better to do an unnecessary build than to miss a doc change.

Test plan

  • Manual trace of the bash logic against representative paths: ✅ passes (Ray serve, RLlib, doc content, .readthedocs.yaml, mixed PRs all trigger BUILD; Java+C++, Docker, release, python/setup.py, empty diff all SKIP).
  • YAML syntax validated locally with yaml.safe_load.
  • This PR itself touches .readthedocs.yaml, so it will exercise the BUILD path on the RTD preview.

Future work

If queue pressure persists after this lands, two further levers:

  1. Narrow the python/ray/** allow-list to exclude paths that don't appear in any autodoc directive (python/ray/tests/, python/ray/_private/ candidates). Higher maintenance cost.
  2. File an RTD support request to ask about the project's concurrent-build limit on the current plan.

Related issues

None linked.

@dstrodtman
dstrodtman marked this pull request as ready for review May 18, 2026 13:52

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a build optimization for ReadTheDocs by adding a post_checkout job that skips Sphinx builds if no documentation-related files are modified. Feedback was provided to include python/setup.py in the list of monitored files, as it is required to correctly determine the project version during the documentation build process.

Comment thread .readthedocs.yaml Outdated
if git merge-base origin/master HEAD >/dev/null 2>&1; then
CHANGED=$(git diff --name-only origin/master...HEAD)
if [ -n "$CHANGED" ] && ! echo "$CHANGED" \
| grep -qE '^(doc/|python/ray/|rllib/|\.readthedocs\.yaml$)'; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current filter excludes python/setup.py, but this file is imported by doc/source/conf.py (line 347) to determine the project version via find_version. Changes to setup.py (such as version bumps or dependency updates) should trigger a documentation build to ensure the version is correctly reflected in the docs and that the build logic remains functional. Please add python/setup.py to the allow-list.

                 | grep -qE '^(doc/|python/ray/|python/setup\.py$|rllib/|\.readthedocs\.yaml$)'; then

@ray-gardener ray-gardener Bot added docs An issue or change related to documentation core Issues that should be addressed in Ray Core devprod labels May 18, 2026
Comment thread .readthedocs.yaml Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit c2f81863e563546066b5e85fdf8886072b5542b3. Configure here.

Comment thread .readthedocs.yaml Resolved
Comment thread .readthedocs.yaml Resolved
Adds a build.jobs.post_checkout job to .readthedocs.yaml that exits
183 (RTD's "cancel build" sentinel) on PR builds when the diff doesn't
touch any files that affect documentation output. Tag and branch
builds (master, stable, etc.) always run.

Today every PR triggers a full Sphinx build regardless of what it
touches. When several PRs are open at once this overflows the
project's concurrent build slots and older queued builds get marked
"terminated due to inactivity" before a worker picks them up.

The doc-affecting allowlist is intentionally broad — any change under
doc/, python/ray/, rllib/, or .readthedocs.yaml itself triggers a
full build. Anything else (C++/Cython under src/cpp, Java, Bazel, CI
infrastructure, release tooling, Docker) skips. A mixed PR with even
one doc-affecting file still builds. The `python/ray/**` and
`rllib/**` paths are included because Sphinx autodoc pulls docstrings
from them; narrowing further would be brittle as new modules are
added.

Auto-cancellation of older builds on the same PR/branch has been on
by default in RTD since Oct 2022. This change complements that by
reducing the load from cross-PR concurrency.

Verified end-to-end on RTD with breadcrumb echos before they were
stripped for this version: CHANGED is populated correctly from
`git diff --name-only origin/master...HEAD` in the shallow-clone
environment, each grep evaluates as expected, and DOC_CHANGED gates
the exit-183 branch. Locally validated across /bin/sh, /bin/dash,
and /bin/bash with a representative diff matrix.

A few shell-construct choices in this script work around non-obvious
processing quirks observed in RTD's job runner: `echo "$VAR"` instead
of `printf '%s\n' "$VAR"` (backslash escapes in single-quoted strings
are eaten before reaching the shell), `[.]` character classes instead
of `\.` (same reason), no shell comments inside the `|` block (a
comment containing backticks or `$()` causes the script to be dropped
silently), and no grouped regex inside a `$()` capture. The
YAML-level comments above the block document this so the constraints
aren't lost in a future cleanup.

See https://docs.readthedocs.com/platform/stable/guides/build/skip-build.html

Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman force-pushed the djs-260518-rtd-skip-non-doc-builds branch from 6e2e763 to 8f9d2d2 Compare May 18, 2026 17:25
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jun 2, 2026
Comment thread .readthedocs.yaml
# for literal dots in regexes (not \.), and keep shell comments out
# of this block so that backticks/$() inside comments don't confuse
# the preprocessor.
post_checkout:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use git diff here instead

      post_checkout:
        - |
          if [ "${READTHEDOCS_VERSION_TYPE:-}" != "external" ]; then
            echo "Not a PR build (version type: '${READTHEDOCS_VERSION_TYPE:-unset}'); building docs."
            exit 0
          fi
          git fetch --depth=500 origin master 2>/dev/null || true
          if ! git merge-base origin/master HEAD >/dev/null 2>&1; then
            echo "Could not determine merge-base with origin/master; building docs to be safe."
            exit 0
          fi
          if git diff --quiet origin/master...HEAD -- doc/ python/ray/ rllib/ .readthedocs.yaml; then
            echo "No doc-affecting files changed in this PR; skipping Sphinx build."
            echo "Files changed in PR:"
            git diff --name-only origin/master...HEAD
            exit 183
          fi
          echo "Doc-affecting files changed; building docs. Changed doc-relevant paths:"
          git diff --name-only origin/master...HEAD -- doc/ python/ray/ rllib/ .readthedocs.yaml

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂️

Will apply your change. LMK if there's additional testing I need to do.

Replace the echo|grep chain with a single pathspec-limited
git diff --quiet, per review feedback. Same skip/build decisions
for all prefix and boundary cases, with one behavior fix: a file
renamed out of a doc-affecting path now triggers a build. Rename
detection made the unfiltered --name-only output report only the
destination path, so the grep filter missed the removal; the
pathspec-limited diff sees the deletion side.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman

Copy link
Copy Markdown
Contributor Author

@elliot-barn Seems to be working per RtD logs, but hasn't been tested on a changed that safely can skip RtD build. Also: because the rules are so broad (include anything that touches Python source code because of API ref generation), not really sure how valuable this is, regardless. Might at least reduce noise on some infra/dependency only changes

@dstrodtman dstrodtman added go add ONLY when ready to merge, run all tests and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Jun 2, 2026
@elliot-barn
elliot-barn merged commit a9b7ff6 into ray-project:master Jun 3, 2026
4 checks passed
rueian pushed a commit to rueian/ray that referenced this pull request Jun 4, 2026
…roject#63431)

## Description

Adds a `build.jobs.post_checkout` block to `.readthedocs.yaml` that
exits with code 183 on PR ("external") builds when the diff doesn't
touch any files that affect documentation output. Tag and branch builds
(master, stable, etc.) always run.

## Why

Today, every PR to `ray-project/ray` triggers a full Sphinx build on
Read the Docs, regardless of what the PR touches. A PR that only changes
C++, Java, Bazel, release tooling, or CI config produces the same docs
build as a PR that rewrites `doc/`.

When several PRs land in quick succession, this overflows the project's
concurrent build slots on RTD. RTD's `finish_inactive_builds` periodic
task then marks the older queued builds as `FAILED` with the message
*"This build was terminated due to inactivity"* (see
[readthedocs.org#4386](readthedocs/readthedocs.org#4386)
— the name is misleading; the build isn't inactive, it just couldn't get
a worker within ~1080 seconds). Contributors then see red checks on
their PRs that have nothing to do with their changes.

[Auto-cancellation of older builds for the same
PR](https://blog.readthedocs.com/cancel-old-builds/) has been on by
default in RTD since October 2022, but that only helps when you push
twice to one PR — not across multiple open PRs. This change complements
that by reducing the load from cross-PR concurrency.

## What the filter does

On every PR build, it computes the diff against `origin/master` and
exits 183 — RTD's [skip-build
sentinel](https://docs.readthedocs.com/platform/stable/guides/build/skip-build.html)
— only when **none** of the changed files match:

- `doc/` — Sphinx sources, BUILD files, doc-only requirements.
- `python/ray/` — anything `autodoc` could pull (kept intentionally
broad).
- `rllib/` — same.
- `.readthedocs.yaml` — this config itself, so changes to it always
test.

If even one file falls in the allow-list, the build runs as before. If
the diff can't be computed (shallow clone, fetch failure), the build
runs.

## What this skips in practice

PRs that don't touch any of the four paths above. Concrete examples:

- C++ / Cython changes under `src/`, `cpp/`.
- Java changes under `java/`.
- Bazel changes under `bazel/`, top-level `BUILD.bazel`, `WORKSPACE`.
- CI changes under `ci/`, `.buildkite/` (except
`.buildkite/doc.rayci.yml` which isn't read by Sphinx but is excluded
from the allow-list since it doesn't change RTD output).
- Release tooling under `release/`.
- Docker changes under `docker/`.
- Top-level scripts and configs.

## What still triggers a build

- All content under `doc/`.
- Any `python/ray/**` change, because `autodoc` could pick it up.
- Any `rllib/**` change, same reason.
- The RTD config itself.

The filter is deliberately conservative — broad inclusion, narrow
exclusion. Better to do an unnecessary build than to miss a doc change.

## Test plan

- Manual trace of the bash logic against representative paths: ✅ passes
(Ray serve, RLlib, doc content, `.readthedocs.yaml`, mixed PRs all
trigger BUILD; Java+C++, Docker, release, `python/setup.py`, empty diff
all SKIP).
- YAML syntax validated locally with `yaml.safe_load`.
- This PR itself touches `.readthedocs.yaml`, so it will exercise the
BUILD path on the RTD preview.

## Future work

If queue pressure persists after this lands, two further levers:

1. Narrow the `python/ray/**` allow-list to exclude paths that don't
appear in any `autodoc` directive (`python/ray/tests/`,
`python/ray/_private/` candidates). Higher maintenance cost.
2. File an RTD support request to ask about the project's
concurrent-build limit on the current plan.

## Related issues

None linked.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
limarkdcunha pushed a commit to limarkdcunha/ray that referenced this pull request Jun 30, 2026
…roject#63431)

## Description

Adds a `build.jobs.post_checkout` block to `.readthedocs.yaml` that
exits with code 183 on PR ("external") builds when the diff doesn't
touch any files that affect documentation output. Tag and branch builds
(master, stable, etc.) always run.

## Why

Today, every PR to `ray-project/ray` triggers a full Sphinx build on
Read the Docs, regardless of what the PR touches. A PR that only changes
C++, Java, Bazel, release tooling, or CI config produces the same docs
build as a PR that rewrites `doc/`.

When several PRs land in quick succession, this overflows the project's
concurrent build slots on RTD. RTD's `finish_inactive_builds` periodic
task then marks the older queued builds as `FAILED` with the message
*"This build was terminated due to inactivity"* (see
[readthedocs.org#4386](readthedocs/readthedocs.org#4386)
— the name is misleading; the build isn't inactive, it just couldn't get
a worker within ~1080 seconds). Contributors then see red checks on
their PRs that have nothing to do with their changes.

[Auto-cancellation of older builds for the same
PR](https://blog.readthedocs.com/cancel-old-builds/) has been on by
default in RTD since October 2022, but that only helps when you push
twice to one PR — not across multiple open PRs. This change complements
that by reducing the load from cross-PR concurrency.

## What the filter does

On every PR build, it computes the diff against `origin/master` and
exits 183 — RTD's [skip-build
sentinel](https://docs.readthedocs.com/platform/stable/guides/build/skip-build.html)
— only when **none** of the changed files match:

- `doc/` — Sphinx sources, BUILD files, doc-only requirements.
- `python/ray/` — anything `autodoc` could pull (kept intentionally
broad).
- `rllib/` — same.
- `.readthedocs.yaml` — this config itself, so changes to it always
test.

If even one file falls in the allow-list, the build runs as before. If
the diff can't be computed (shallow clone, fetch failure), the build
runs.

## What this skips in practice

PRs that don't touch any of the four paths above. Concrete examples:

- C++ / Cython changes under `src/`, `cpp/`.
- Java changes under `java/`.
- Bazel changes under `bazel/`, top-level `BUILD.bazel`, `WORKSPACE`.
- CI changes under `ci/`, `.buildkite/` (except
`.buildkite/doc.rayci.yml` which isn't read by Sphinx but is excluded
from the allow-list since it doesn't change RTD output).
- Release tooling under `release/`.
- Docker changes under `docker/`.
- Top-level scripts and configs.

## What still triggers a build

- All content under `doc/`.
- Any `python/ray/**` change, because `autodoc` could pick it up.
- Any `rllib/**` change, same reason.
- The RTD config itself.

The filter is deliberately conservative — broad inclusion, narrow
exclusion. Better to do an unnecessary build than to miss a doc change.

## Test plan

- Manual trace of the bash logic against representative paths: ✅ passes
(Ray serve, RLlib, doc content, `.readthedocs.yaml`, mixed PRs all
trigger BUILD; Java+C++, Docker, release, `python/setup.py`, empty diff
all SKIP).
- YAML syntax validated locally with `yaml.safe_load`.
- This PR itself touches `.readthedocs.yaml`, so it will exercise the
BUILD path on the RTD preview.

## Future work

If queue pressure persists after this lands, two further levers:

1. Narrow the `python/ray/**` allow-list to exclude paths that don't
appear in any `autodoc` directive (`python/ray/tests/`,
`python/ray/_private/` candidates). Higher maintenance cost.
2. File an RTD support request to ask about the project's
concurrent-build limit on the current plan.

## Related issues

None linked.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…roject#63431)

## Description

Adds a `build.jobs.post_checkout` block to `.readthedocs.yaml` that
exits with code 183 on PR ("external") builds when the diff doesn't
touch any files that affect documentation output. Tag and branch builds
(master, stable, etc.) always run.

## Why

Today, every PR to `ray-project/ray` triggers a full Sphinx build on
Read the Docs, regardless of what the PR touches. A PR that only changes
C++, Java, Bazel, release tooling, or CI config produces the same docs
build as a PR that rewrites `doc/`.

When several PRs land in quick succession, this overflows the project's
concurrent build slots on RTD. RTD's `finish_inactive_builds` periodic
task then marks the older queued builds as `FAILED` with the message
*"This build was terminated due to inactivity"* (see
[readthedocs.org#4386](readthedocs/readthedocs.org#4386)
— the name is misleading; the build isn't inactive, it just couldn't get
a worker within ~1080 seconds). Contributors then see red checks on
their PRs that have nothing to do with their changes.

[Auto-cancellation of older builds for the same
PR](https://blog.readthedocs.com/cancel-old-builds/) has been on by
default in RTD since October 2022, but that only helps when you push
twice to one PR — not across multiple open PRs. This change complements
that by reducing the load from cross-PR concurrency.

## What the filter does

On every PR build, it computes the diff against `origin/master` and
exits 183 — RTD's [skip-build
sentinel](https://docs.readthedocs.com/platform/stable/guides/build/skip-build.html)
— only when **none** of the changed files match:

- `doc/` — Sphinx sources, BUILD files, doc-only requirements.
- `python/ray/` — anything `autodoc` could pull (kept intentionally
broad).
- `rllib/` — same.
- `.readthedocs.yaml` — this config itself, so changes to it always
test.

If even one file falls in the allow-list, the build runs as before. If
the diff can't be computed (shallow clone, fetch failure), the build
runs.

## What this skips in practice

PRs that don't touch any of the four paths above. Concrete examples:

- C++ / Cython changes under `src/`, `cpp/`.
- Java changes under `java/`.
- Bazel changes under `bazel/`, top-level `BUILD.bazel`, `WORKSPACE`.
- CI changes under `ci/`, `.buildkite/` (except
`.buildkite/doc.rayci.yml` which isn't read by Sphinx but is excluded
from the allow-list since it doesn't change RTD output).
- Release tooling under `release/`.
- Docker changes under `docker/`.
- Top-level scripts and configs.

## What still triggers a build

- All content under `doc/`.
- Any `python/ray/**` change, because `autodoc` could pick it up.
- Any `rllib/**` change, same reason.
- The RTD config itself.

The filter is deliberately conservative — broad inclusion, narrow
exclusion. Better to do an unnecessary build than to miss a doc change.

## Test plan

- Manual trace of the bash logic against representative paths: ✅ passes
(Ray serve, RLlib, doc content, `.readthedocs.yaml`, mixed PRs all
trigger BUILD; Java+C++, Docker, release, `python/setup.py`, empty diff
all SKIP).
- YAML syntax validated locally with `yaml.safe_load`.
- This PR itself touches `.readthedocs.yaml`, so it will exercise the
BUILD path on the RTD preview.

## Future work

If queue pressure persists after this lands, two further levers:

1. Narrow the `python/ray/**` allow-list to exclude paths that don't
appear in any `autodoc` directive (`python/ray/tests/`,
`python/ray/_private/` candidates). Higher maintenance cost.
2. File an RTD support request to ask about the project's
concurrent-build limit on the current plan.

## Related issues

None linked.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: 400Ping <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core devprod docs An issue or change related to documentation go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants