Skip to content

Commit 84c0ff0

Browse files
committed
Update configuration to build only on changes to docs files
1 parent 06ffcc1 commit 84c0ff0

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

.readthedocs.yaml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ build:
1010
os: ubuntu-22.04
1111
tools:
1212
python: "3.12"
13-
# nodejs: "19"
14-
commands:
15-
- make rtd-pr-preview
16-
17-
# Build documentation in the "docs/" directory with Sphinx
18-
#sphinx:
19-
# configuration: docs/conf.py
20-
21-
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
22-
#python:
23-
# install:
24-
# - requirements: docs/requirements.txt
13+
jobs:
14+
post_checkout:
15+
# Cancel building pull requests when there aren't changes in the docs directory or YAML file.
16+
# You can add any other files or directories that you'd like here as well,
17+
# like your docs requirements file, or other files that will change your docs build.
18+
#
19+
# If there are no changes (git diff exits with 0) we force the command to return with 183.
20+
# This is a special exit code on Read the Docs that will cancel the build immediately.
21+
- |
22+
if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- docs/ .readthedocs.yaml requirements-initial.txt requirements.txt;
23+
then
24+
exit 183;
25+
fi
26+
- make rtd-pr-preview

docs/contributing/documentation/admins.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,35 @@ You can do this through your {file}`.readthedocs.yaml` file.
153153
Read the Docs covers a few scenarios in its documentation, [Cancel build based on a condition](https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition).
154154
155155
156+
#### Build only on changes
157+
158+
When there are no changes to documentation, it is not necessary to build it.
159+
You can save time and energy by programmatically building documentation only when it changes.
160+
161+
In your {file}`.readthedocs.yaml` file, you could use the following example.
162+
163+
```yaml
164+
version: 2
165+
build:
166+
os: "ubuntu-22.04"
167+
tools:
168+
python: "3.12"
169+
jobs:
170+
post_checkout:
171+
# Cancel building pull requests when there aren't changes in the docs directory or YAML file.
172+
# You can add any other files or directories that you'd like here as well,
173+
# like your docs requirements file, or other files that will change your docs build.
174+
#
175+
# If there are no changes (git diff exits with 0) we force the command to return with 183.
176+
# This is a special exit code on Read the Docs that will cancel the build immediately.
177+
- |
178+
if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- docs/ .readthedocs.yaml requirements-initial.txt requirements.txt;
179+
then
180+
exit 183;
181+
fi
182+
```
183+
184+
156185
#### Cancel builds on a branch
157186

158187
If you have pull request preview builds enabled, any pull request to any branch will trigger a build.

0 commit comments

Comments
 (0)