Skip to content

Commit 1031389

Browse files
authored
chore: cancel build on Read the Docs conditionally (#406)
1 parent 51ed166 commit 1031389

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

.github/workflows/readthedocs-preview.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ on:
1818
- .readthedocs.yaml
1919
- README.md
2020
- docs/**
21+
- pdm.lock
2122
permissions:
2223
pull-requests: write

.readthedocs.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ build:
66
post_checkout:
77
- env | sort
88
- git fetch --unshallow || true
9+
# Cancel building pull requests when there aren't changed in the related files and folders.
10+
# If there are no changes (git diff exits with 0) we force the command to return with 183.
11+
# This is a special exit code on Read the Docs that will cancel the build immediately.
12+
# Ref: https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition
13+
- |
14+
if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- .github/workflows/readthedocs-preview.yml .readthedocs.yaml README.md docs/ pdm.lock;
15+
then
16+
exit 183;
17+
fi
918
post_install:
1019
- python -m pip install --upgrade --no-cache-dir pdm
1120
- PDM_NO_EDITABLE=true make dev-doc

template/.readthedocs.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ build:
66
post_checkout:
77
- env | sort
88
- git fetch --unshallow || true
9+
# Cancel building pull requests when there aren't changed in the related files and folders.
10+
# If there are no changes (git diff exits with 0) we force the command to return with 183.
11+
# This is a special exit code on Read the Docs that will cancel the build immediately.
12+
# Ref: https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition
13+
- |
14+
if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- .github/workflows/readthedocs-preview.yml .readthedocs.yaml README.md docs/ pdm.lock;
15+
then
16+
exit 183;
17+
fi
918
post_install:
1019
- python -m pip install --upgrade --no-cache-dir pdm
1120
- PDM_NO_EDITABLE=true make dev-doc

template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ on:
1818
- .readthedocs.yaml
1919
- README.md
2020
- docs/**
21+
- pdm.lock
2122
permissions:
2223
pull-requests: write

0 commit comments

Comments
 (0)