Skip to content

Commit 768e894

Browse files
humitosbenjaoming
andauthored
Docs: cancel PR builds if there is no documentation changes (#9734)
* Docs: cancel PR builds if there is no documentation changes Use the new feature to cancel builds if there are not documentation changes * Use quotes to make the script valid * Change logic to use $? (last exit code) in the condition We don't have to exit the command immediately when `git diff` exists with 1; that means there are changes and we want to continue building the documentation. * Modify if statement * Update docs to use the new command * Update .readthedocs.yml Co-authored-by: Benjamin Balder Bach <[email protected]> Co-authored-by: Benjamin Balder Bach <[email protected]>
1 parent a609d9a commit 768e894

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

.readthedocs.yml

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ build:
1414
os: ubuntu-22.04
1515
tools:
1616
python: "3.10"
17+
jobs:
18+
post_checkout:
19+
# https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition
20+
#
21+
# Cancel building pull requests when there aren't changed in the docs directory.
22+
#
23+
# If there are no changes (git diff exits with 0) we force the command to return with 183.
24+
# This is a special exit code on Read the Docs that will cancel the build immediately.
25+
- |
26+
if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- docs/;
27+
then
28+
echo "No changes to docs/ - exiting the build.";
29+
exit 183;
30+
fi
1731
1832
search:
1933
ranking:

docs/user/build-customization.rst

+3-5
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,13 @@ Here is an example that cancels builds from pull requests when there are no chan
140140
jobs:
141141
post_checkout:
142142
# Cancel building pull requests when there aren't changed in the docs directory.
143-
# `--quiet` exits with a 1 when there **are** changes,
144-
# so we invert the logic with a !
145143
#
146-
# If there are no changes (exit 0) we force the command to return with 183.
144+
# If there are no changes (git diff exits with 0) we force the command to return with 183.
147145
# This is a special exit code on Read the Docs that will cancel the build immediately.
148146
- |
149-
if [ $READTHEDOCS_VERSION_TYPE = "external" ];
147+
if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- docs/;
150148
then
151-
! git diff --quiet origin/main -- docs/ && exit 183;
149+
exit 183;
152150
fi
153151
154152

0 commit comments

Comments
 (0)