diff --git a/.readthedocs.yml b/.readthedocs.yml index a0bb3ee62da..da2c49d042d 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -14,6 +14,20 @@ 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. + # + # 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/; + then + echo "No changes to docs/ - exiting the build."; + exit 183; + fi search: ranking: diff --git a/docs/user/build-customization.rst b/docs/user/build-customization.rst index 18d56fa8a72..5f6ce025ca7 100644 --- a/docs/user/build-customization.rst +++ b/docs/user/build-customization.rst @@ -140,15 +140,13 @@ 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" ]; + if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- docs/; then - ! git diff --quiet origin/main -- docs/ && exit 183; + exit 183; fi