From cd0651913ea6cebcd534e7964dc89a9b9701d390 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Tue, 15 Nov 2022 11:44:21 +0100 Subject: [PATCH 1/6] Docs: cancel PR builds if there is no documentation changes Use the new feature to cancel builds if there are not documentation changes --- .readthedocs.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.readthedocs.yml b/.readthedocs.yml index a0bb3ee62da..cc315548a43 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -14,6 +14,21 @@ build: os: ubuntu-22.04 tools: python: "3.10" + jobs: + post_checkout: + # https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition + # + # Cancel building pull requests when there aren't changed in the docs directory. + # `--quiet` exits with a 1 when there **are** changes, + # so we invert the logic with a ! + # + # If there are no changes (exit 0) we force the command to return with 183. + # This is a special exit code on Read the Docs that will cancel the build immediately. + - | + if [ $READTHEDOCS_VERSION_TYPE = "external" ]; + then + ! git diff --quiet origin/main -- docs/ && exit 183; + fi search: ranking: From 66a78c63b9f1ba5dd55528f80d54185b0a25ffb3 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Tue, 22 Nov 2022 15:15:11 +0100 Subject: [PATCH 2/6] Use quotes to make the script valid --- .readthedocs.yml | 2 +- docs/user/build-customization.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index cc315548a43..5b39f8ce2b6 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -25,7 +25,7 @@ build: # If there are no changes (exit 0) we force the command to return with 183. # This is a special exit code on Read the Docs that will cancel the build immediately. - | - if [ $READTHEDOCS_VERSION_TYPE = "external" ]; + if [ "$READTHEDOCS_VERSION_TYPE" = "external" ]; then ! git diff --quiet origin/main -- docs/ && exit 183; fi diff --git a/docs/user/build-customization.rst b/docs/user/build-customization.rst index 18d56fa8a72..879280e207f 100644 --- a/docs/user/build-customization.rst +++ b/docs/user/build-customization.rst @@ -146,7 +146,7 @@ Here is an example that cancels builds from pull requests when there are no chan # If there are no changes (exit 0) we force the command to return with 183. # This is a special exit code on Read the Docs that will cancel the build immediately. - | - if [ $READTHEDOCS_VERSION_TYPE = "external" ]; + if [ "$READTHEDOCS_VERSION_TYPE" = "external" ]; then ! git diff --quiet origin/main -- docs/ && exit 183; fi From becdae1b2facaecb6b4d12672b40f60879c1bb70 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Tue, 22 Nov 2022 15:52:42 +0100 Subject: [PATCH 3/6] 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. --- .readthedocs.yml | 9 ++++----- docs/user/build-customization.rst | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 5b39f8ce2b6..ee95f754872 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -19,15 +19,14 @@ build: # https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition # # Cancel building pull requests when there aren't changed in the docs directory. - # `--quiet` exits with a 1 when there **are** changes, - # so we invert the logic with a ! # - # If there are no changes (exit 0) we force the command to return with 183. + # If there are no changes (git diff exits with 0) we force the command to return with 183. # This is a special exit code on Read the Docs that will cancel the build immediately. - | - if [ "$READTHEDOCS_VERSION_TYPE" = "external" ]; + git diff --quiet origin/main -- docs/ + if [ "$READTHEDOCS_VERSION_TYPE" = "external" && $? -eq 0 ]; then - ! git diff --quiet origin/main -- docs/ && exit 183; + exit 183; fi search: diff --git a/docs/user/build-customization.rst b/docs/user/build-customization.rst index 879280e207f..3a5ca012be2 100644 --- a/docs/user/build-customization.rst +++ b/docs/user/build-customization.rst @@ -140,15 +140,14 @@ Here is an example that cancels builds from pull requests when there are no chan jobs: post_checkout: # Cancel building pull requests when there aren't changed in the docs directory. - # `--quiet` exits with a 1 when there **are** changes, - # so we invert the logic with a ! # - # If there are no changes (exit 0) we force the command to return with 183. + # If there are no changes (git diff exits with 0) we force the command to return with 183. # This is a special exit code on Read the Docs that will cancel the build immediately. - | - if [ "$READTHEDOCS_VERSION_TYPE" = "external" ]; + git diff --quiet origin/main -- docs/ + if [ "$READTHEDOCS_VERSION_TYPE" = "external" && $? -eq 0 ]; then - ! git diff --quiet origin/main -- docs/ && exit 183; + exit 183; fi From bb658585b50054f08345747a66223a6df684ea1b Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Tue, 22 Nov 2022 15:59:41 +0100 Subject: [PATCH 4/6] Modify if statement --- .readthedocs.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index ee95f754872..2700b24eebb 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -23,8 +23,7 @@ build: # If there are no changes (git diff exits with 0) we force the command to return with 183. # This is a special exit code on Read the Docs that will cancel the build immediately. - | - git diff --quiet origin/main -- docs/ - if [ "$READTHEDOCS_VERSION_TYPE" = "external" && $? -eq 0 ]; + if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- docs/; then exit 183; fi From 1e07857ab4cdc86a5e4f5749193a9ea40741ad49 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Tue, 22 Nov 2022 16:02:09 +0100 Subject: [PATCH 5/6] Update docs to use the new command --- docs/user/build-customization.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/user/build-customization.rst b/docs/user/build-customization.rst index 3a5ca012be2..5f6ce025ca7 100644 --- a/docs/user/build-customization.rst +++ b/docs/user/build-customization.rst @@ -144,8 +144,7 @@ Here is an example that cancels builds from pull requests when there are no chan # If there are no changes (git diff exits with 0) we force the command to return with 183. # This is a special exit code on Read the Docs that will cancel the build immediately. - | - git diff --quiet origin/main -- docs/ - if [ "$READTHEDOCS_VERSION_TYPE" = "external" && $? -eq 0 ]; + if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- docs/; then exit 183; fi From 5f04fe2ffeb7e3afc79f0f1996031d5b52cb1bc8 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Tue, 22 Nov 2022 16:26:08 +0100 Subject: [PATCH 6/6] Update .readthedocs.yml Co-authored-by: Benjamin Balder Bach --- .readthedocs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.readthedocs.yml b/.readthedocs.yml index 2700b24eebb..da2c49d042d 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -25,6 +25,7 @@ build: - | if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- docs/; then + echo "No changes to docs/ - exiting the build."; exit 183; fi