cli
cli copied to clipboard
fix: fixed 1st deploy race condition when generating site from a template
๐ Thanks for submitting a pull request! ๐
Summary
Fixes #4212
As the issue explains, there is a race condition that occasionally occurs on the first deployment of a site when using the CLI command ntl sites:create-template.
Currently the CLI clones a repo using GitHub's API via the template endpoint.
https://github.com/netlify/cli/blob/7ffcbdfbdb5ccbc7e82a3550e46412b380e7d9e6/src/utils/sites/utils.js#L34-L47
The repository is created and the proper information is returned, but sometimes the refs aren't available right away when the repository is cloned when the site is being created.
Doing an explicit call to get the repository information after it's been created appears to fix the issue. My assumption is the repo is fully formed at this point, i.e. no Failed during stage 'preparing repo': git ref refs/heads/main does not exist error.
QA Instructions, Screenshots, Recordings
- Pull down this PR, e.g. via GitHub CLI
gh co 4607 - Follow the https://github.com/netlify/cli#development steps to get set up to test the PR
- run
ntl sites:create-templatefrom the shell - Select any template. It doesn't matter which one.
- Answer no for the step about cloning the repository.
- Repeat steps 1-5 a bunch of times.
- Head to your overview page, e.g. https://app.netlify.com/teams/your-team/overview, to see if any of your initial deployments fail. They shouldn't ๐ค๐ป
For us to review and ship your PR efficiently, please perform the following steps:
- [x] Open a bug/issue before writing your code ๐งโ๐ป. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire ๐ฅ (e.g. incident related), you can skip this step.
- [x] Read the contribution guidelines ๐. This ensures your code follows our style guide and passes our tests.
- [ ] Update or add tests (if any source code was changed or added) ๐งช
- [ ] Update or add documentation (if features were changed or added) ๐
- [ ] Make sure the status checks below are successful โ
A picture of a cute animal (not mandatory, but encouraged)

๐ Benchmark results
Comparing with 9f04bb0180fc06ec50faad590df689678fc272c3
Package size: 287 MB
โฌ๏ธ 0.00% decrease vs. 9f04bb0180fc06ec50faad590df689678fc272c3
^ 286 MB 286 MB 286 MB 286 MB 286 MB 286 MB 285 MB 285 MB 285 MB 285 MB 285 MB 285 MB 287 MB
โ โโโโ โโโโ โโโโ โโโโ โโโโ โโโโ โโโโ โโโโ โโโโ โโโโ โโโโ โโโโ โโโโ
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โ | | | | | | | | | | | | | | | | | | | | | | | | |โโ|
โโโโโดโโโดโโโโโดโโโดโโโโโดโโโดโโโโโดโโโดโโโโโดโโโดโโโโโดโโโดโโโโโดโโโดโโโโโดโโโดโโโโโดโโโดโโโโโดโโโดโโโโโดโโโดโโโโโดโโโดโโโโโดโโโดโโ>
T-12 T-11 T-10 T-9 T-8 T-7 T-6 T-5 T-4 T-3 T-2 T-1 T
Legend
- T-30 (9f04bb0180fc06ec50faad590df689678fc272c3): 287 MB
- T-29 (19f6ea58c2e564acf7f2fabc0b7d86b9432f59fb): 287 MB
- T-28 (9173d13413d700da5c663dba140da58bb3c926bd): 287 MB
- T-27 (f8e692fc4efb7a76ea6ab5b97747903e0d7b54b9): 287 MB
- T-26 (441d7ff9de56f693d8067217d2b5256c34c37260): 287 MB
- T-25 (5d5aeae83ebb6253f92fb4db757e7fb24eabd1a0): 287 MB
- T-24 (9b70a1ba05598f041ef367c01056c764320b514d): 287 MB
- T-23 (ae382d1b244caaaaeeb58df732413f603f563521): 287 MB
- T-22 (00091467e84c803e440983bda83169764e442e0c): 287 MB
- T-21 (5f217e56e41a39b8f62d6b2bbbd5cbe545e87c65): 287 MB
- T-20 (ad23be386b9c3c72d38e6cd21f94fdcd9e07891d): 286 MB
- T-19 (7bdf548405299a1eb031c3e5c3ef0ff27285674d): 286 MB
- T-18 (a139ef195822e3d7c2024f225c5a91434024eb05): 286 MB
- T-17 (a4c9dbbb9e731b386fe6d23c81c775278fe6ac6c): 286 MB
- T-16 (b6d76e876757e5cefd01932c3aa4011bd3d4a702): 286 MB
- T-15 (0845e8091a82187d02bde59bd543ee9675cb6c06): 286 MB
- T-14 (3e43d9ab3bfe073251dd2ad006690d6bf1b16c5b): 286 MB
- T-13 (d017df9f61f7135a0a568f7cc426e35c363af75e): 286 MB
- T-12 (216631a62c08572ba18b0c770da97d6dcbe1229b): 286 MB
- T-11 (f5b1ab558bd24fe7414019c46ce3e977f1bd22ff): 286 MB
- T-10 (ae4d49be1a3d073ad810f3dd31b18a7730f8be7e): 286 MB
- T-9 (7c5156d429754db5da1f16391b5f2febe22ebeea): 286 MB
- T-8 (c6fd8a6e2fb1015aacee659c6739a38a24406adb): 286 MB
- T-7 (9faabf31590ab4b8c877ddc4df6cb2e12c067f31): 286 MB
- T-6 (1956c51c6937cc25fe31a76aa88f025e9a18a10f): 285 MB
- T-5 (e3ffcb1eebf7e01b39fa224968ccb781e9864b97): 285 MB
- T-4 (a31d411a96cd6f62babd78b5a2a447cf0ddd120f): 285 MB
- T-3 (d35f7e0510051007af51f4069a04dc5659cf7f8c): 285 MB
- T-2 (f4ee7a433d9e417ac11c2f362cdf2063fb888f45): 285 MB
- T-1 (73b2d6ac2b5721da2bd16b4881b2f81f69a94fe7): 285 MB
- T (current commit): 287 MB
Not sure if this is a known issue or it's just my PR, but he CLI fails to install for Mac
โ yarn โ should install the cli and run the help command (1m 5.2s)
โ
pnpm โ should install the cli and run the help command
Rejected promise returned by test. Reason:
Error {
command: 'pnpm add http://localhost:8840/netlify-cli/-/netlify-cli-10.3.1.tgz',
escapedCommand: 'pnpm add "http://localhost:8840/netlify-cli/-/netlify-cli-10.3.1.tgz"',
exitCode: 1,
failed: true,
isCanceled: false,
killed: false,
shortMessage: 'Command failed with exit code 1: pnpm add http://localhost:8840/netlify-cli/-/netlify-cli-10.3.1.tgz',
signal: undefined,
signalDescription: undefined,
stderr: undefined,
stdout: undefined,
timedOut: false,
message: 'Command failed with exit code 1: pnpm add http://localhost:8840/netlify-cli/-/netlify-cli-10.3.1.tgz',
}
โบ makeError (node_modules/execa/lib/error.js:60:11)
โบ handlePromise (node_modules/execa/index.js:118:26)
โบ async file://e2e/install.e2e.mjs:31:5
โ
1 test failed
Command failed with exit code 1: ava **/*.e2e.mjs --config /Users/runner/work/cli/cli/e2e.config.mjs
Error: Process completed with exit code 1.
I'm going to go ahead and close this, because one it's been stale for a while, but also, I'm still not positive this solves the issue.