-
-
Notifications
You must be signed in to change notification settings - Fork 730
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
Update setup script with newest template and merge with old script #10529
Conversation
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.
LGTM!
👌
Thanks! 😎
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 like the idea to have a single, modern setup script. However I think we're losing some advantages of the old script.
Can we incorporate them into one?
Or what if we updated script/setup
to first call bin/setup
, then run the extra improvements on top of that. Then bin/setup
can remain as the Rails template.
bin/setup
Outdated
# Install JavaScript dependencies if using Yarn | ||
# system('bin/yarn') | ||
# Install JavaScript dependencies | ||
system("yarn") |
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.
We do have a bin/yarn
script, so why not use that as per the template? (although I'm not sure it really provides any benefit)
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, the next commit provides a clue. It's not quite as quick.
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.
Oh, I didn't actually see that we had bin/yarn
. I'll revise this commit.
|
||
# Set up Ruby dependencies via Bundler | ||
if ! command -v bundle > /dev/null; then | ||
./script/install-bundler |
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.
This script actually checks the Bundler version, and installs new versions if needed, whereas bin/setup doesn't. I think it would be good to incorporate that to be more idempotent.
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.
Somehow I thought that newer version of bundler automatically use the right version but that doesn't seem to be true. I misremembered the logic of https://bundler.io/guides/bundler_2_upgrade.html#version-autoswitch.
So yes, we should run this as well.
RUBY_VERSION=$(cat .ruby-version) | ||
|
||
# Check ruby version | ||
if ! ruby --version | grep $RUBY_VERSION > /dev/null; then |
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.
This check seems pretty useful. I would suggest we keep it.
I can also see possibility to improve and add a node version check also.
Maybe even conditionally run rbenv and nodenv if installed.
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.
Good point. When I removed that I thought that we can just run script/rbenv-install
but then I realised that this bin/setup
is a Ruby script and won't run before installing ruby. And even when Ruby and rbenv are present then rbenv complaints that it can't find the right version.
So maybe that's another reason to keep script/setup to run the ruby installation.
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.
Thank you for the thorough review. I will make some changes and ping you again for re-review before rewriting history.
bin/setup
Outdated
# Install JavaScript dependencies if using Yarn | ||
# system('bin/yarn') | ||
# Install JavaScript dependencies | ||
system("yarn") |
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.
Oh, I didn't actually see that we had bin/yarn
. I'll revise this commit.
RUBY_VERSION=$(cat .ruby-version) | ||
|
||
# Check ruby version | ||
if ! ruby --version | grep $RUBY_VERSION > /dev/null; then |
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.
Good point. When I removed that I thought that we can just run script/rbenv-install
but then I realised that this bin/setup
is a Ruby script and won't run before installing ruby. And even when Ruby and rbenv are present then rbenv complaints that it can't find the right version.
So maybe that's another reason to keep script/setup to run the ruby installation.
|
||
# Set up Ruby dependencies via Bundler | ||
if ! command -v bundle > /dev/null; then | ||
./script/install-bundler |
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.
Somehow I thought that newer version of bundler automatically use the right version but that doesn't seem to be true. I misremembered the logic of https://bundler.io/guides/bundler_2_upgrade.html#version-autoswitch.
So yes, we should run this as well.
e925887
to
ce10adf
Compare
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.
Great, I think I found a bug though.
I note that bin/setup
has some variations from the default now, which might not be obvious if updating for a new version in the future. But I doubt this matters.
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 used the script from a new Rails 7 project.
The $ sign used to indicate shell commands. But with markdown it's obvious that we are entering commands. Github has a quick copy button for all code examples which used to copy the $ sign as well. Removing it allows to copy and paste easier with that button.
The command is switching to an unprivileged user which can't access /root and therefore there was a warning when executing. Adding `--login` to the sudo command switches to that user properly and avoids the warning.
People may use other ways to provide the right Ruby version but if they use rbenv then we can use it automatically.
Not just when it's missing.
And remove duplicate output. `bin/setup` is the Rails default for updating your environment after code updates and `script/setup` is our convenience script for the initial setup and starting with sample data.
I'm guessing just rebased? Except that I think the sample_data task is not quite robust enough. My dev data seems to have broken it:
Looks like I have an outgoing exchange with no variants which has tripped it up. But I think that's a problem with that task, so all good! ✅ |
Thanks. Merging. |
What? Why?
setup/script
#7624Rails has a default location for setup scripts and newer versions are idempotent. You can use them to update your app as well. It helps devs to run all needed commands after switching branches.
What should we test?
Dev Test
./bin/setup
and everything should work../script/setup
and it should work as well.Release notes
Changelog Category: Technical changes
The title of the pull request will be included in the release notes.
Dependencies
Documentation updates