From cb7f1b1f0b9d50ae8a923043d0ed77b2171bf59f Mon Sep 17 00:00:00 2001 From: David Angulo Date: Mon, 21 Nov 2022 05:59:19 -0800 Subject: [PATCH] Read `.ruby-version` file in `Gemfile` (#35410) Summary: When updating the Ruby version, 2 files are always needed to be updated (`.ruby-version` and `Gemfile`). When not in sync it can lead to an error like `Your Ruby version is 2.7.6, but your Gemfile specified 2.7.5`. This lessens the files that need to be updated when upgrading the Ruby version and makes it in sync always. It makes the `.ruby-version` the source of truth. ### Example 1: Screenshot 2022-11-20 at 13 56 08 When upgrading from `0.70.0` to `0.71.0-rc.0`. 2 files needs to be updated when it could have been just 1. Source: https://react-native-community.github.io/upgrade-helper/?from=0.70.0&to=0.71.0-rc.0 ### Example 2: 21c8837c1264cd96f5899e33132fa764bb9c2293 updates 4 files (`.ruby-version`, `Gemfile`, `template/Gemfile`, `template/_ruby-version`) when it could have been just 2. ### Other Sources: * https://andycroll.com/ruby/read-ruby-version-in-your-gemfile/ * https://render.com/docs/ruby-version (Heroku alternative) * https://stackoverflow.com/a/35823132/9375533 ## Changelog [General] [Changed] - Read `.ruby-version` file in `Gemfile` Pull Request resolved: https://github.com/facebook/react-native/pull/35410 Test Plan: Only `.ruby-version` and `template/_ruby-version` needs to be updated when upgrading Ruby version. Reviewed By: christophpurrer, cipolleschi Differential Revision: D41429147 Pulled By: rshest fbshipit-source-id: 9e541a1d84aed5dca1e6f465c61bb0ba15574211 --- Gemfile | 2 +- scripts/update-ruby.sh | 7 +------ template/Gemfile | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index b15113b7e057d4..567e59805c4a73 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version -ruby '2.7.6' +ruby File.read(File.join(__dir__, '.ruby-version')).strip gem 'cocoapods', '~> 1.11', '>= 1.11.3' diff --git a/scripts/update-ruby.sh b/scripts/update-ruby.sh index 20ab62ca9e9f02..2e8f39bb74be45 100755 --- a/scripts/update-ruby.sh +++ b/scripts/update-ruby.sh @@ -50,9 +50,6 @@ fi echo "$VERSION" > template/_ruby-version -sed_i -e "s/^\(ruby '\)[^']*\('.*\)$/\1$VERSION\2/" Gemfile -sed_i -e "s/^\(ruby '\)[^']*\('.*\)$/\1$VERSION\2/" template/Gemfile - rm -f Gemfile.lock export BUNDLE_APP_CONFIG="$ROOT/.bundle" @@ -67,10 +64,8 @@ export GIT_DISCOVERY_ACROSS_FILESYSTEM=0; if [ "$IS_GIT_REPO" = "true" ]; then git add \ .ruby-version \ - Gemfile \ Gemfile.lock \ - template/_ruby-version \ - template/Gemfile + template/_ruby-version else echo "Detected that you're not in Git. If on another SCM, don't forget to commit the edited files." fi diff --git a/template/Gemfile b/template/Gemfile index b15113b7e057d4..567e59805c4a73 100644 --- a/template/Gemfile +++ b/template/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version -ruby '2.7.6' +ruby File.read(File.join(__dir__, '.ruby-version')).strip gem 'cocoapods', '~> 1.11', '>= 1.11.3'