diff --git a/.github/workflows/readthedocs-preview.yml b/.github/workflows/readthedocs-preview.yml index 110b4887..4a7d39e4 100644 --- a/.github/workflows/readthedocs-preview.yml +++ b/.github/workflows/readthedocs-preview.yml @@ -18,5 +18,6 @@ on: - .readthedocs.yaml - README.md - docs/** + - pdm.lock permissions: pull-requests: write diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 929a6438..102c2794 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -6,6 +6,15 @@ build: post_checkout: - env | sort - git fetch --unshallow || true + # Cancel building pull requests when there aren't changed in the related files and folders. + # 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. + # Ref: https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition + - | + if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- .github/workflows/readthedocs-preview.yml .readthedocs.yaml README.md docs/ pdm.lock; + then + exit 183; + fi post_install: - python -m pip install --upgrade --no-cache-dir pdm - PDM_NO_EDITABLE=true make dev-doc diff --git a/template/.readthedocs.yaml b/template/.readthedocs.yaml index 929a6438..102c2794 100644 --- a/template/.readthedocs.yaml +++ b/template/.readthedocs.yaml @@ -6,6 +6,15 @@ build: post_checkout: - env | sort - git fetch --unshallow || true + # Cancel building pull requests when there aren't changed in the related files and folders. + # 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. + # Ref: https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition + - | + if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- .github/workflows/readthedocs-preview.yml .readthedocs.yaml README.md docs/ pdm.lock; + then + exit 183; + fi post_install: - python -m pip install --upgrade --no-cache-dir pdm - PDM_NO_EDITABLE=true make dev-doc diff --git a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja index 3a4545f2..e1883529 100644 --- a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja +++ b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja @@ -18,5 +18,6 @@ on: - .readthedocs.yaml - README.md - docs/** + - pdm.lock permissions: pull-requests: write