Skip to content

Commit bb72d07

Browse files
authored
Add initial attempt to keep working dir (#12327)
For Enterprise users with dedicated builders, keeping the checkout around can make their build much faster, especially in the case of a monorepo. This is just a draft PR to start testing this concept. Locally: <img width="1137" height="360" alt="Screenshot 2025-07-16 at 2 58 48 PM" src="https://github.com/user-attachments/assets/1deed038-b7df-4958-877e-828163e7cea3" />
1 parent 80a0a42 commit bb72d07

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

readthedocs/projects/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,7 @@ def add_features(sender, **kwargs):
19701970
# Build related features
19711971
SCALE_IN_PROTECTION = "scale_in_prtection"
19721972
USE_S3_SCOPED_CREDENTIALS_ON_BUILDERS = "use_s3_scoped_credentials_on_builders"
1973+
DONT_CLEAN_BUILD = "dont_clean_build"
19731974
BUILD_HEALTHCHECK = "build_healthcheck"
19741975
BUILD_NO_ACKS_LATE = "build_no_acks_late"
19751976

@@ -2026,6 +2027,10 @@ def add_features(sender, **kwargs):
20262027
_("Build: Use S3 scoped credentials for uploading build artifacts."),
20272028
),
20282029
(
2030+
DONT_CLEAN_BUILD,
2031+
_(
2032+
"Build: Don't clean the build directory. Only for Enterprise users with dedicated builders."
2033+
),
20292034
BUILD_HEALTHCHECK,
20302035
_("Build: Use background cURL healthcheck."),
20312036
),

readthedocs/projects/tasks/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727

2828
def clean_build(version):
2929
"""Clean the files used in the build of the given version."""
30+
from readthedocs.projects.models import Feature
31+
32+
if version.project.has_feature(
33+
Feature.DONT_CLEAN_BUILD,
34+
):
35+
log.info(
36+
"Skipping cleaning build files for project with DONT_CLEAN_BUILD feature.",
37+
project_slug=version.project.slug,
38+
version_slug=version.slug,
39+
)
40+
return
41+
3042
del_dirs = [
3143
os.path.join(version.project.doc_path, dir_, version.slug)
3244
for dir_ in ("checkouts", "envs", "conda", "artifacts")

readthedocs/vcs_support/backends/git.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Git-related utilities."""
22

3+
import os
34
import re
45
from typing import Iterable
56
from urllib.parse import urlparse
@@ -43,6 +44,14 @@ def update(self):
4344
"""Clone and/or fetch remote repository."""
4445
super().update()
4546

47+
# Check for existing checkout and skip clone if it exists.
48+
from readthedocs.projects.models import Feature
49+
50+
if self.project.has_feature(Feature.DONT_CLEAN_BUILD) and os.path.exists(
51+
os.path.join(self.working_dir, ".git")
52+
):
53+
return self.fetch()
54+
4655
self.clone()
4756
# TODO: We are still using return values in this function that are legacy.
4857
# This should be either explained or removed.

0 commit comments

Comments
 (0)