Skip to content
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

Build: skip checkout step when building latest without an explicit default branch #10927

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Nov 27, 2023

So, first I was trying to fix the whole webhook/build out of sync with latest, but there are several parts where default branch is set to work in some way, bogus way sometimes, but anyway. Instead of trying to solve the whole thing right now, I'm just doing two things:

  • Instead of having the special case of latest identifier being None to skip the checkout step, we check for the default_branch option instead. If the default branch isn't set, it means the user wants to use the default clone branch, and instead of having to worry about keeping in for the checkout command to work, we just skip the checkout, since the default branch is already in use after cloning the repo.
  • We still need to keep latest in sync with the version it points to, since that value is used in several other parts of the codebase. If the user has an explicit default branch set, that's easy, since we just take a look at that version and use that information to sync latest with, but if the user doesn't have a default branch set, we have no idea about the current default branch of the repository, we are relying on webhooks to keep this up to date, but if the repo is imported manually, and doesn't have an integration attached, RTD doesn't know what the default branch of the repo is. Git allows us to get the default branch of the repo, so now we are using that to keep latest in sync with the current default branch.

The second change probably makes updating the default branch from the webhook useless. We should probably invest a little more of time on re-structuring how latest works and how we keep it in sync, for now I just want to unblock users importing projects manually without an explicit default branch.

There's still the problem about latest's identifier being out of sync when the default branch changes, but that's fixed after a new build, and this isn't a new problem, as it's present in the current implementation (and now users aren't blocked at least), and changing the default branch of a repo isn't something users do that often, so I think we are okay with that for now.

Extra fixes:

  • Set the type of latest to branch when updating from the default branch (since here it's actually a branch!)
  • Always check for latest/stable and machine=True, since otherwise the versions are user-managed, and they behave as normal versions instead of rtd-managed ones.
  • Include -- to end positional arguments in all git commands, this isn't a security issue, as all the git commands are run inside docker.

Closes #10915

@stsewd stsewd changed the title Build: fix mismatch between webhook and version sync for latest Build: skip checkout step when building latest without an explicit default branch Nov 30, 2023
@stsewd stsewd marked this pull request as ready for review November 30, 2023 21:32
@stsewd stsewd requested a review from a team as a code owner November 30, 2023 21:32
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good change... this is mostly just to fix the issue where people change their default branch and get stuck (eg. master -> main)?

Comment on lines +652 to +653
# Update the latest version to point to the current default branch
# if the project doesn't have a default branch set.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Update the latest version to point to the current default branch
# if the project doesn't have a default branch set.
# Update the latest version to point to the current VCS default branch
# if the project doesn't have an explicit default branch set.

Comment on lines +202 to +204
is_rtd_latest = (
self.verbose_name == LATEST_VERBOSE_NAME and self.version_machine
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is repeated 5 times in this PR... should it just be a method on self here, so that we don't have it defined in different ways?

cmd = ["git", "symbolic-ref", "--short", "refs/remotes/origin/HEAD"]
_, stdout, _ = self.run(*cmd, demux=True, record=False)
default_branch = stdout.strip().removeprefix("origin/")
return default_branch or self.fallback_branch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we not have a default_branch here?

@humitos
Copy link
Member

humitos commented Feb 20, 2024

Is this PR still relevant? I'm not sure to understand exactly what problem does it solves and how many users are affected by this. My feeling with this is that each time we touch the code on how we clone the versions we break someones' pattern 🙃 --so I'd be a little conservative here if it doesn't affect too many users.

@stsewd
Copy link
Member Author

stsewd commented Feb 20, 2024

This is still valid. This solves the problem when people change their default branch, or when they manually import a project without having a default branch set explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mismatch when updating latest via webhook and after clone
3 participants