-
-
Notifications
You must be signed in to change notification settings - Fork 9k
refactor: optimize clone and checkout in deploy command #5829
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
refactor: optimize clone and checkout in deploy command #5829
Conversation
✔️ [V2] 🔨 Explore the source changes: a2e29b0 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/618c703775757000082a5add 😎 Browse the preview: https://deploy-preview-5829--docusaurus-2.netlify.app |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-5829--docusaurus-2.netlify.app/ |
This kind of code is not so easy to review for me. Can you describe exactly what I should do locally to test this? |
|
I think this can be further simplified by removing the if (shellExecLog(`git clone --depth 1 --branch ${deploymentBranch} ${remoteBranch} ${toPath}`).code == 0) { // Attempt cloning specified deployment branch
shell.cd(toPath); // If deployment branch clone is successful, cd to directory
} else if (shellExecLog(`git clone --depth 1 ${remoteBranch} ${toPath}`).code == 0) { // If deployment branch clone fails, attempt cloning repo's default branch
shell.cd(toPath); // If default branch clone is successful, cd to directory
if (shellExecLog(`git checkout --orphan ${deploymentBranch}`).code !== 0) { // Check out an orphan branch for deployment
throw new Error(`Running "git checkout ${deploymentBranch}" command failed.`); // Throw error if checkout command fails
}
} else {
throw new Error(`Running "git clone" command in "${toPath}" failed.`); // Throw error if both clone commands fail
} If no errors have been thrown, these prerequisites are now completed (and it should be ready to proceed with the subsequent steps):
Current code that achieves the same: docusaurus/packages/docusaurus/src/commands/deploy.ts Lines 175 to 211 in 41ef9da
|
@sivapalan Are you going to do the refactor yourself, since it seems you do have a clear plan in mind? I also suggest you add some inline comments explaining each step so it will be easier for the reviewers and future code readers. |
I was just waiting for some input from you guys, regarding if this refactoring is wanted or not before doing any further work on this 🙂 I think there's also another additional simplification that can be done, but not sure if it's preferred or not. If the This is now done in the latest commit: 63334e2 I've not added any error handling for the newly added commands:
Can these be considered "safe" as they don't do any remote calls, or should we add checks for the exit codes before continuing? |
The idea looks very good to me, and it makes the code much easier to understand. 👍 I don't think we need error handling in those three commands. We don't do it for |
In the future @slorber if we have a Docusaurus org, we should make a few site fixture repos and test E2E on those fixtures, including |
Motivation
The fix in #5828 was probably the safest and quickest solution for the bug that was causing either deployment failures or overwriting of commit history. But, as mentioned in that PR description, an alternative and more optimized solution would be to specify
--branch ${deploymentBranch}
for theclone
command and thereby skip thecheckout
step altogether (except for the initial deployment where an orphan branch will have to be checked out).Let me know if there are any edge cases I've missed or any side effects that should be taken into consideration for this change.
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Tested command locally.
Related PRs
#5828