readthedocs / readthedocs.org

The source code that powers readthedocs.org
https://readthedocs.org/
MIT License
7.99k stars 3.58k forks source link

'exit 183' is not cancelling the build #11353

Closed Gabriel-p closed 3 months ago

Gabriel-p commented 3 months ago

Details

Expected Result

I'm using the code shown here https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition to cancel builds when the /docs folder of my develop branch is not changed. Here's my .readthedocs.yaml:

# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
  os: ubuntu-22.04
  tools:
    python: "3.12"
    # You can also specify other tool versions:
    # nodejs: "20"
    # rust: "1.70"
    # golang: "1.20"
  jobs:
    post_checkout:
      # Cancel building pull requests when there aren't changes in the docs directory or YAML file.
      # You can add any other files or directories that you'd like here as well,
      # like your docs requirements file, or other files that will change your docs 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.
      - |
        if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/develop -- docs/ .readthedocs.yaml;
        then
          exit 183;
        fi

# Build documentation in the "docs/" directory with Sphinx
sphinx:
  configuration: docs/conf.py
  # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
  # builder: "dirhtml"
  # Fail on all warnings to avoid broken references
  # fail_on_warning: true

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
#   - pdf
#   - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
  install:
    - requirements: docs/requirements.txt

Actual Result

The build does not halt when I modify files outside of the /docs folder, as shown in the build https://readthedocs.org/projects/asteca/builds/24475781/ triggered by this commit

stsewd commented 3 months ago

Hi, if [ "$READTHEDOCS_VERSION_TYPE" = "external" that means that it only applies on builds from PRs, if you want to cancel builds that aren't from PRs too, you can remove that first condition.

Gabriel-p commented 3 months ago

Oh I see! I did not get that from the docs, thank you!

Gabriel-p commented 3 months ago

One more question @stsewd , is there a way to force the build when I manually trigger it from within my project even with that code in the yaml file?

stsewd commented 3 months ago

One more question @stsewd , is there a way to force the build when I manually trigger it from within my project even with that code in the yaml file?

No out of the box, maybe you can hack it with an environment variable that you manually add to your project when you want to force a build.

Gabriel-p commented 3 months ago

Sorry to bother you @stsewd but I'm stuck again.

Now it's cancelling the build https://readthedocs.org/projects/asteca/builds/24476240/ even when I'm clearly modifying contents in /docs https://github.com/asteca/ASteCA/commit/9264712fe551e967f68e975cea1524a8f537224e