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

Rewrite monorepo install script #36584

Open
wants to merge 18 commits into
base: trunk
Choose a base branch
from

Conversation

tbradsha
Copy link
Contributor

@tbradsha tbradsha commented Mar 26, 2024

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.

@tbradsha tbradsha requested a review from a team March 26, 2024 15:00
@tbradsha tbradsha self-assigned this Mar 26, 2024
Copy link
Contributor

github-actions bot commented Mar 26, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.

@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Mar 26, 2024
@tbradsha tbradsha added [Status] Needs Team Review and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Mar 26, 2024
@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Mar 26, 2024
@tbradsha tbradsha removed the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Mar 26, 2024
Copy link
Contributor

@anomiex anomiex left a 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 Show resolved Hide resolved
tools/install-monorepo.sh Outdated Show resolved Hide resolved
tools/install-monorepo.sh Outdated Show resolved Hide resolved
tools/install-monorepo.sh Show resolved Hide resolved
tools/install-monorepo.sh Outdated Show resolved Hide resolved
tools/install-monorepo.sh Outdated Show resolved Hide resolved
tools/install-monorepo.sh Outdated Show resolved Hide resolved
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.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

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).

Copy link
Contributor Author

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. 🤔

Copy link
Contributor

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).

tools/install-monorepo.sh Show resolved Hide resolved
tools/install-monorepo.sh Outdated Show resolved Hide resolved
@kraftbj kraftbj added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Tools] Monorepo Setup labels Mar 26, 2024
fi
do_system
do_basics
do_homebrew
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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 and do_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?

@kraftbj
Copy link
Contributor

kraftbj commented Mar 27, 2024

I tried this on an Ubuntu VM (via Parallels on Mac) that was fresh enough I never installed git on it.

I had to manually install curl. At least for Ubuntu, it would be a sudo apt install curl.

When trying to install pnpm:
2024-03-26 at 16 50

It continued with the script; would have missed it if I wasn't babysitting it. Trying to rerun it does hard fail.
2024-03-26 at 16 55

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 npm and directly installed pnpm via npm.

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 -y or something like that to keep it moving.

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 Error: Too many open files, but restarting gets past it (this might be a VM issue).

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.

@anomiex
Copy link
Contributor

anomiex commented Mar 27, 2024

It ended with an error Error: Too many open files, but restarting gets past it (this might be a VM issue).

Seems like something homebrew doesn't want to fix: Homebrew/brew#9120

@tbradsha
Copy link
Contributor Author

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?

@kraftbj
Copy link
Contributor

kraftbj commented Mar 27, 2024

I'm fine with chopping it until if/when we decide to Really Do It™.

@anomiex
Copy link
Contributor

anomiex commented Mar 27, 2024

Removing it sounds good to me too.

tbradsha and others added 12 commits March 27, 2024 18:36
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>
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
@tbradsha
Copy link
Contributor Author

tbradsha commented Mar 28, 2024

When trying to install pnpm:

It seems perhaps you're running on trunk, as the error message I see in your screenshot is no longer present:

warn 'pnpm has no bin dir set, and `pnpm setup` failed. Linking the Jetpack CLI may fail.'

The other pnpm error seems related to homebrew (per the linked issue), which this script doesn't use. 🤔

Each time I start the script, I need to ack the install prompt for homebrew, even though it is installed already.

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:

else
info "Updating brew"
brew update
# Brew can be finicky on MacOS
if [[ $? -ne 0 ]]; then
echo "Reinstalling Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
fi

That's one of the many weird things I dealt with when trying to run the script that prompted this PR.

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?

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. :^)

tbradsha and others added 2 commits March 28, 2024 09:24
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
tools/install-monorepo.sh Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Needs Team Review [Tools] Monorepo Setup [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants