-
-
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
Open
stsewd
wants to merge
18
commits into
main
Choose a base branch
from
skip-checkout-for-latest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
dbae5b4
Build: skip checkout for latest when no default version is given
stsewd 0074e5e
Merge branch 'main' into skip-checkout-for-latest
stsewd 24854de
Fix tests
stsewd 9572098
Keep latest in sync with default branch
stsewd 082b1be
Format
stsewd 77ae232
Fix tests
stsewd f636eb9
Test
stsewd 8701e3c
Fix tests
stsewd 9903db6
Merge branch 'main' into skip-checkout-for-latest
stsewd 335fff8
Format
stsewd c7e0087
We don't need this
stsewd c9e7138
Default branch should be resolved before checkout
stsewd 1723c27
Fix order again
stsewd 68b4405
Merge branch 'main' into skip-checkout-for-latest
stsewd 722617c
Comment
stsewd a3374b5
Skip checkout
stsewd 23da415
Merge branch 'main' into skip-checkout-for-latest
stsewd 882d98c
Merge branch 'main' into skip-checkout-for-latest
stsewd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
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 |
||
|
|
||
| # 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 | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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).