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
Rewrite monorepo install script #36584
base: trunk
Are you sure you want to change the base?
Conversation
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped. |
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.
Gave it a fairly thorough look-through, and test in an Ubuntu docker container. You'll want to get Mac users to test it there though.
Feel free to disagree with any of my comments, as usual. 🙂
tools/install-monorepo.sh
Outdated
if ! has_command php || [[ $(php -r "echo version_compare(PHP_VERSION,'$PHP_VERSION');") -eq -1 ]]; then | ||
echo "PHP $PHP_VERSION: not found" | ||
|
||
# Note that we can't use grep -v, as it's prematurely terminated. |
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.
"prematurely terminated"?
More likely grep -v
wouldn't work because it'd always succeed unless php@8.2 or whatever is the only thing installed via brew, since it'd match every non-"php@8.2" line in the output.
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.
The comment had a typo: cc42fbc
I meant to say grep -q
. See also:
https://stackoverflow.com/questions/67681070/zsh-brew-list-any-command-raises-uncaught-signal-pipe-error
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.
Ah. Is brew printing that error message, or zsh? We do similar things in other bash scripts in various places with no problem (or with just a || true
to fix the exit code for -eo pipefail
).
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.
It's brew
that prints it:
https://github.com/Homebrew/brew/blob/821f67ff6db8d4a5b08010d065166faa979e72bf/Library/Homebrew/exceptions.rb#L670-L678
As a more general note: I'm not sure how a || true
would help with grep -q
, as we'd want a non-zero exit code from grep -q
if not found. 🤔
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.
As a more general note: I'm not sure how a || true would help with grep -q, as we'd want a non-zero exit code from grep -q if not found. 🤔
I was thinking of cases like VAR=$( ... | grep 'something' )
, where if the ...
bit SIGPIPEs then -eo pipefail
would make the script exit.
OTOH, even then { ... || true; } | grep -q
could be a trick to use so we only get the exit code from grep
and not ...
(pipefail or otherwise).
fi | ||
do_system | ||
do_basics | ||
do_homebrew |
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.
I tried this on my existing system so it had nothing to do, but there was a decent delay between the output of do_basics
and do_homebrew
and another decent wait for do_nvm
. Everything else felt "instant". Not sure if either of the commands could check faster (again in this case, they were already installed at sufficient versions) or if we can let folks know what's happening and that the script didn't hang.
I could see this being as simple as an info "Checking OS"
, info "Checking Git and Curl"
, info Checking for Homebrew
, etc. I like the UX of an indicator but I am not married to that idea at all.
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.
I'll find an old laptop, wipe it, and try it on a fresh fresh system (at least at whatever Mac OS version the old laptop supports) tonight or tomorrow.
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.
there was a decent delay between the output of
do_basics
anddo_homebrew
Not sure if either of the commands could check faster
Yes, this is because it runs brew update
silently, but I'll look into making a few things more verbose and perhaps move the brew update
to only run when installing.
another decent wait for
do_nvm
This one's a bit odd...it grabs a GH release URL, but that should be pretty quick in most cases. Perhaps a hiccup? Does it still do this?
I tried this on an Ubuntu VM (via Parallels on Mac) that was fresh enough I never installed I had to manually install It continued with the script; would have missed it if I wasn't babysitting it. Trying to rerun it does hard fail. I'm not sure how Parallels works under the hood, but it may be related to this pnpm/pnpm#6424 (comment) To keep being able to test the script, I installed Each time I start the script, I need to ack the install prompt for homebrew, even though it is installed already. EOD for me, so didn't look to see if that's intentional (to keep running the homebrew install) so either need to check in a different way or at least see if we can pass a I forget how long this takes. We could add a disclaimer/ack at the top "if you're running this on a new machine, it might take awhile. Start it and go get a cup of coffee" (assuming the non-interactive is set). It ended with an error At the end, it has green text saying that I need to restart my terminal, followed by terminal refreshed. Is the refresh handling the restart? Do I still need to restart? tools/check-development-environment.sh returned (almost) all green (no docker) without a restart. |
Seems like something homebrew doesn't want to fix: Homebrew/brew#9120 |
Thanks for the reviews/testing; I'll look over this later today. I know Linux support isn't the priority here; the only reason I kept Linux support is because it was explicitly included in the old version of the script (with a fair number of issues), but removing it would definitely simplify things. @kraftbj and @anomiex should I just chop it? |
I'm fine with chopping it until if/when we decide to Really Do It™. |
Removing it sounds good to me too. |
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
It seems perhaps you're running on jetpack/tools/install-monorepo.sh Line 99 in 8d7171a
The other
Yes, this was one of the annoying things about the old script; it would reinstall things that already existed, so it points to you running the old version of the script: jetpack/tools/install-monorepo.sh Lines 54 to 62 in 8d7171a
That's one of the many weird things I dealt with when trying to run the script that prompted this PR.
The old script would pseudo-refresh the terminal; in reality it just opened a subshell, which I think is even messier. The prompt now explicitly states "You will need to restart your terminal". One of the reasons I prefer sourcing scripts instead of executing them is because it can modify the immediate environment (and preventing the need to open a new terminal, for example), but convention in the monorepo seems to be executables (see also Automattic/social-logos#132 (comment)). Though I guess this is all somewhat irrelevant now that I've chopped Linux support. :^) |
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
While working through the setup docs, I tried to use the install script for the first time, and ran into dozens of hiccups on Mac on Linux. It also previously ran a lot of extra commands when unneeded, and didn't consistently set up the environment across shells. I went ahead and rewrote the install script; it's a bit verbose, but should be a bit more usable.
I don't account for all edge cases, but it should be robust enough, and should readily exit if something looks broken.
Given we run this in as an executable (i.e. in a subshell), restarting the terminal is required if environmental vars are changed. This was always the case.
Does this pull request change what data or activity we track or use?
Nope.
Testing instructions:
If you already have everything set up, you should be able to run the script and it should run through without any needed changes.
However, feel free to try on a stock macOS or Debian-based distro and ensure things run smoothly.