-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Build: better support for empty default branch #12462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 9 commits
dbae5b4
0074e5e
24854de
9572098
082b1be
77ae232
f636eb9
8701e3c
9903db6
335fff8
c7e0087
c9e7138
1723c27
68b4405
722617c
a3374b5
23da415
882d98c
6c14ed4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| from readthedocs.builds import tasks as build_tasks | ||
| from readthedocs.builds.constants import ARTIFACT_TYPES | ||
| from readthedocs.builds.constants import ARTIFACT_TYPES_WITHOUT_MULTIPLE_FILES_SUPPORT | ||
| from readthedocs.builds.constants import BRANCH | ||
| from readthedocs.builds.constants import BUILD_FINAL_STATES | ||
| from readthedocs.builds.constants import BUILD_STATE_BUILDING | ||
| from readthedocs.builds.constants import BUILD_STATE_CANCELLED | ||
|
|
@@ -115,6 +116,10 @@ class TaskData: | |
| config: BuildConfigV2 = None | ||
| project: APIProject = None | ||
| version: APIVersion = None | ||
| # Default branch for the repository. | ||
| # Only set when building the latest version, and the project | ||
| # doesn't have an explicit default branch. | ||
| default_branch: str | None = None | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we call it more explicitly like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @stsewd
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the same? |
||
|
|
||
| # Dictionary returned from the API. | ||
| build: dict = field(default_factory=dict) | ||
|
|
@@ -644,18 +649,22 @@ def on_success(self, retval, task_id, args, kwargs): | |
| # NOTE: we are updating the db version instance *only* when | ||
| # TODO: remove this condition and *always* update the DB Version instance | ||
| if "html" in valid_artifacts: | ||
| data = { | ||
| "built": True, | ||
| "documentation_type": self.data.version.documentation_type, | ||
| "has_pdf": "pdf" in valid_artifacts, | ||
| "has_epub": "epub" in valid_artifacts, | ||
| "has_htmlzip": "htmlzip" in valid_artifacts, | ||
| "build_data": self.data.version.build_data, | ||
| "addons": self.data.version.addons, | ||
| } | ||
| # Update the latest version to point to the current VCS default branch | ||
| # if the project doesn't have an explicit default branch set. | ||
| if self.data.default_branch: | ||
| data["identifier"] = self.data.default_branch | ||
| data["type"] = BRANCH | ||
| try: | ||
| self.data.api_client.version(self.data.version.pk).patch( | ||
| { | ||
| "built": True, | ||
| "documentation_type": self.data.version.documentation_type, | ||
| "has_pdf": "pdf" in valid_artifacts, | ||
| "has_epub": "epub" in valid_artifacts, | ||
| "has_htmlzip": "htmlzip" in valid_artifacts, | ||
| "build_data": self.data.version.build_data, | ||
| "addons": self.data.version.addons, | ||
| } | ||
| ) | ||
| self.data.api_client.version(self.data.version.pk).patch(data) | ||
| except HttpClientError: | ||
| # NOTE: I think we should fail the build if we cannot update | ||
| # the version at this point. Otherwise, we will have inconsistent data | ||
|
|
@@ -803,6 +812,15 @@ def execute(self): | |
| with self.data.build_director.vcs_environment: | ||
| self.data.build_director.setup_vcs() | ||
|
|
||
| # Get the default branch of the repository if the project doesn't | ||
| # have an explicit default branch set and we are building latest. | ||
| # The identifier from latest will be updated with this value | ||
| # if the build succeeds. | ||
| if self.data.version.is_machine_latest and not self.data.project.default_branch: | ||
| self.data.default_branch = ( | ||
| self.data.build_director.vcs_repository.get_default_branch() | ||
| ) | ||
|
|
||
| # Sync tags/branches from VCS repository into Read the Docs' | ||
| # `Version` objects in the database. This method runs commands | ||
| # (e.g. "hg tags") inside the VCS environment, so it requires to be | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is introducing an extra query for each time latest is returned in a response, since we now rely on latest having the correct value of the default branch (similar to get_original_stable_version).