Skip to content

Commit 1dcc546

Browse files
zwarewebknjaz
andauthored
Rewrite RTD configuration to use build.jobs rather than build.commands (GH-149429)
As part of this conversion, we now ensure that we're comparing against the merge-base of the PR branch and the base branch when checking whether an RTD build is worthwhile, deepening the history of the base branch by up to 500 commits if necessary. If the merge-base can't be found or there are merge conflicts with the head of the base branch, the build is skipped since it would give a warped perception of the actual changes anyway. This unfortunately does nothing about RTD preview comments comparing against the wrong base, other than skipping builds that shouldn't produce any diff at all thus avoiding the comment. Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
1 parent 4ed4014 commit 1dcc546

1 file changed

Lines changed: 44 additions & 20 deletions

File tree

.readthedocs.yml

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,47 @@ build:
1212
tools:
1313
python: "3"
1414

15-
commands:
16-
# https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition
17-
#
18-
# Cancel building pull requests when there aren't changes in the Doc directory.
19-
#
20-
# If there are no changes (git diff exits with 0) we force the command to return with 183.
21-
# This is a special exit code on Read the Docs that will cancel the build immediately.
22-
- |
23-
if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && [ "$(git diff --quiet origin/main -- Doc/ .readthedocs.yml; echo $?)" -eq 0 ];
24-
then
25-
echo "No changes to Doc/ - exiting the build.";
26-
exit 183;
27-
fi
28-
29-
- asdf plugin add uv
30-
- asdf install uv latest
31-
- asdf global uv latest
32-
- make -C Doc venv html
33-
- mkdir _readthedocs
34-
- mv Doc/build/html _readthedocs/html
15+
jobs:
16+
post_checkout:
17+
# https://docs.readthedocs.com/platform/stable/guides/build/skip-build.html#skip-builds-based-on-conditions
18+
#
19+
# Cancel building pull requests when there aren't changes in the Doc
20+
# directory or RTD configuration, or if we can't cleanly merge the base
21+
# branch.
22+
- |
23+
set -eEux;
24+
if [ "$READTHEDOCS_VERSION_TYPE" = "external" ];
25+
then
26+
base_branch=main;
27+
git fetch --depth=50 origin $base_branch:origin-$base_branch;
28+
for attempt in $(seq 10);
29+
do
30+
if ! git merge-base HEAD origin-$base_branch;
31+
then
32+
git fetch --deepen=50 origin $base_branch;
33+
else
34+
break;
35+
fi;
36+
done;
37+
if ! git -c "user.name=rtd" -c "user.email=no-reply@readthedocs.org" merge --no-stat --no-edit origin-$base_branch;
38+
then
39+
echo "Unsuccessful merge with '$base_branch' branch, skipping the build";
40+
exit 183;
41+
fi;
42+
if git diff --exit-code --stat origin-$base_branch -- Doc/ .readthedocs.yml;
43+
then
44+
echo "No changes to Doc/ - skipping the build.";
45+
exit 183;
46+
fi;
47+
fi;
48+
create_environment:
49+
- echo "Skipping default environment creation"
50+
install:
51+
- asdf plugin add uv
52+
- asdf install uv latest
53+
- asdf global uv latest
54+
build:
55+
html:
56+
- make -C Doc venv html
57+
- mkdir -p "$READTHEDOCS_OUTPUT"
58+
- mv Doc/build/html "$READTHEDOCS_OUTPUT/"

0 commit comments

Comments
 (0)