From f9fb0e0deb0c52f36e8aa8d16c1edfb652b10093 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Fri, 3 May 2024 14:18:55 -0300 Subject: [PATCH 01/13] Read Ruby version from Gemfile.lock --- .github/workflows/test.yml | 12 ++++++++++++ .ruby-version | 2 +- .tool-versions | 3 ++- README.md | 11 ++++++----- action.yml | 2 +- dist/index.js | 27 ++++++++++++++++++++++++++- gemfiles/ruby-version.gemfile | 3 +++ gemfiles/ruby-version.gemfile.lock | 15 +++++++++++++++ index.js | 27 ++++++++++++++++++++++++++- 9 files changed, 92 insertions(+), 10 deletions(-) create mode 100644 gemfiles/ruby-version.gemfile create mode 100644 gemfiles/ruby-version.gemfile.lock diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2ea9b0995..25f2ad0e1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -217,6 +217,18 @@ jobs: rubygems: 3.2.3 - run: gem --version | grep -F "3.3.3" + testRubyVersionFromGemfile: + name: "Test RUBY VERSION from Gemfile.lock" + runs-on: ubuntu-latest + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/ruby-version.gemfile + steps: + - uses: actions/checkout@v4 + - uses: ./ + with: + ruby-version: gemfile + - run: ruby --version | grep -F "3.3.1" + testUseBundlerFromRubyGemsUpdate: name: "Test rubygems: version uses the Bundler installed by the rubygems update" runs-on: ubuntu-latest diff --git a/.ruby-version b/.ruby-version index d7edb5686..4a85a55cf 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-2.6.5 +ruby-3.3.1 diff --git a/.tool-versions b/.tool-versions index 20e3745aa..bfb55a217 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,3 @@ nodejs 16.0.0 -ruby 2.7.0 +yarn 1.22.19 +ruby 3.3.1 diff --git a/README.md b/README.md index 210abe24e..f8a37d869 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ This action currently supports these versions of MRI, JRuby and TruffleRuby: | `truffleruby` | 19.3.0 - 24.0.1, head | | `truffleruby+graalvm` | 21.2.0 - 24.0.1, head | -`ruby-debug` is the same as `ruby-head` but with assertions enabled (`-DRUBY_DEBUG=1`). +`ruby-debug` is the same as `ruby-head` but with assertions enabled (`-DRUBY_DEBUG=1`). Regarding Windows ruby master builds, `mingw` is a MSYS2/MinGW build, `head` & `ucrt` are MSYS2/UCRT64 builds, and `mswin` is a MSVC/VS 2022 build. @@ -135,7 +135,8 @@ and the [condition and expression syntax](https://help.github.com/en/actions/ref * engine only like `ruby` and `truffleruby`, uses the latest stable release of that implementation * `.ruby-version` reads from the project's `.ruby-version` file * `.tool-versions` reads from the project's `.tool-versions` file -* If the `ruby-version` input is not specified, `.ruby-version` is tried first, followed by `.tool-versions` +* `gemfile` reads from the project's `Gemfile.lock` file +* If the `ruby-version` input is not specified, `.ruby-version` is tried first, followed by `.tool-versions`, then `Gemfile.lock`. ### Working Directory @@ -176,8 +177,8 @@ This action provides a way to automatically run `bundle install` and cache the r Note that any step doing `bundle install` (for the root `Gemfile`) or `gem install bundler` can be removed with `bundler-cache: true`. -This caching speeds up installing gems significantly and avoids too many requests to RubyGems.org. -It needs a `Gemfile` (or `$BUNDLE_GEMFILE` or `gems.rb`) under the [`working-directory`](#working-directory). +This caching speeds up installing gems significantly and avoids too many requests to RubyGems.org. +It needs a `Gemfile` (or `$BUNDLE_GEMFILE` or `gems.rb`) under the [`working-directory`](#working-directory). If there is a `Gemfile.lock` (or `$BUNDLE_GEMFILE.lock` or `gems.locked`), `bundle config --local deployment true` is used. To use a `Gemfile` which is not at the root or has a different name, set `BUNDLE_GEMFILE` in the `env` at the job level @@ -191,7 +192,7 @@ They should be set in the `env` at the job level as shown in the [example](#matr To find the correct the environment variable name, see the [Bundler docs](https://bundler.io/man/bundle-config.1.html) or look at `.bundle/config` after running `bundle config --local KEY VALUE` locally. You might need to `"`-quote the environment variable name in YAML if it has unusual characters like `/`. -To perform caching, this action will use `bundle config --local path $PWD/vendor/bundle`. +To perform caching, this action will use `bundle config --local path $PWD/vendor/bundle`. Therefore, the Bundler `path` should not be changed in your workflow for the cache to work (no `bundle config path`). #### How it Works diff --git a/action.yml b/action.yml index 302149251..c3fa4a568 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,7 @@ branding: icon: download inputs: ruby-version: - description: 'Engine and version to use, see the syntax in the README. Reads from .ruby-version or .tool-versions if unset.' + description: 'Engine and version to use, see the syntax in the README. Reads from .ruby-version, .tool-versions or Gemfile.lock.' default: 'default' rubygems: description: | diff --git a/dist/index.js b/dist/index.js index d91fe36cb..6122c128d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -65844,14 +65844,29 @@ async function setupRuby(options = {}) { core.setOutput('ruby-prefix', rubyPrefix) } +function readRubyVersionFromGemfileLock(lockFile) { + if (lockFile !== null && fs.existsSync(lockFile)) { + const contents = fs.readFileSync(lockFile, 'utf8') + const lines = contents.split(/\r?\n/) + const rubyVersionLine = lines.findIndex(line => /^RUBY VERSION$/.test(line.trim())) + if (rubyVersionLine !== -1) { + const nextLine = lines[rubyVersionLine+1].trim().replace(/p\d+$/, '') // Strip off patchlevel because ruby-builder can't be that precise + return nextLine + } + } + return null +} + function parseRubyEngineAndVersion(rubyVersion) { if (rubyVersion === 'default') { if (fs.existsSync('.ruby-version')) { rubyVersion = '.ruby-version' } else if (fs.existsSync('.tool-versions')) { rubyVersion = '.tool-versions' + } else if (fs.existsSync('Gemfile.lock')) { + rubyVersion = 'gemfile' } else { - throw new Error('input ruby-version needs to be specified if no .ruby-version or .tool-versions file exists') + throw new Error('input ruby-version needs to be specified if no .ruby-version, .tool-versions or Gemfile.lock file exists') } } @@ -65863,12 +65878,20 @@ function parseRubyEngineAndVersion(rubyVersion) { const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s/.test(e))[0] rubyVersion = rubyLine.match(/^ruby\s+(.+)$/)[1] console.log(`Using ${rubyVersion} as input from file .tool-versions`) + } else if (rubyVersion === 'gemfile') { // Read from Gemfile.lock + rubyVersion = readRubyVersionFromGemfileLock('Gemfile.lock') + if (rubyVersion === null) { + throw new Error('Could not find Ruby version in Gemfile.lock') + } + console.log(`Using ${rubyVersion} as input from Gemfile.lock`) } let engine, version if (/^(\d+)/.test(rubyVersion) || common.isHeadVersion(rubyVersion)) { // X.Y.Z => ruby-X.Y.Z engine = 'ruby' version = rubyVersion + } else if (rubyVersion.includes(' ')) { // engine X.Y.Z + [engine, version] = common.partition(rubyVersion, ' ') } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion engine = rubyVersion version = '' // Let the logic in validateRubyEngineAndVersion() find the version @@ -65876,6 +65899,8 @@ function parseRubyEngineAndVersion(rubyVersion) { [engine, version] = common.partition(rubyVersion, '-') } + console.log(`Using ruby engine ${engine} and version ${version}`) + return [engine, version] } diff --git a/gemfiles/ruby-version.gemfile b/gemfiles/ruby-version.gemfile new file mode 100644 index 000000000..65406b780 --- /dev/null +++ b/gemfiles/ruby-version.gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +ruby "3.3.1" diff --git a/gemfiles/ruby-version.gemfile.lock b/gemfiles/ruby-version.gemfile.lock new file mode 100644 index 000000000..7d1fc71b1 --- /dev/null +++ b/gemfiles/ruby-version.gemfile.lock @@ -0,0 +1,15 @@ +GEM + remote: https://rubygems.org/ + specs: + +PLATFORMS + arm64-darwin-23 + ruby + +DEPENDENCIES + +RUBY VERSION + ruby 3.3.1p55 + +BUNDLED WITH + 2.5.9 diff --git a/index.js b/index.js index 743616a5c..b00f963fe 100644 --- a/index.js +++ b/index.js @@ -105,14 +105,29 @@ export async function setupRuby(options = {}) { core.setOutput('ruby-prefix', rubyPrefix) } +function readRubyVersionFromGemfileLock(lockFile) { + if (lockFile !== null && fs.existsSync(lockFile)) { + const contents = fs.readFileSync(lockFile, 'utf8') + const lines = contents.split(/\r?\n/) + const rubyVersionLine = lines.findIndex(line => /^RUBY VERSION$/.test(line.trim())) + if (rubyVersionLine !== -1) { + const nextLine = lines[rubyVersionLine+1].trim().replace(/p\d+$/, '') // Strip off patchlevel because ruby-builder can't be that precise + return nextLine + } + } + return null +} + function parseRubyEngineAndVersion(rubyVersion) { if (rubyVersion === 'default') { if (fs.existsSync('.ruby-version')) { rubyVersion = '.ruby-version' } else if (fs.existsSync('.tool-versions')) { rubyVersion = '.tool-versions' + } else if (fs.existsSync('Gemfile.lock')) { + rubyVersion = 'gemfile' } else { - throw new Error('input ruby-version needs to be specified if no .ruby-version or .tool-versions file exists') + throw new Error('input ruby-version needs to be specified if no .ruby-version, .tool-versions or Gemfile.lock file exists') } } @@ -124,12 +139,20 @@ function parseRubyEngineAndVersion(rubyVersion) { const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s/.test(e))[0] rubyVersion = rubyLine.match(/^ruby\s+(.+)$/)[1] console.log(`Using ${rubyVersion} as input from file .tool-versions`) + } else if (rubyVersion === 'gemfile') { // Read from Gemfile.lock + rubyVersion = readRubyVersionFromGemfileLock('Gemfile.lock') + if (rubyVersion === null) { + throw new Error('Could not find Ruby version in Gemfile.lock') + } + console.log(`Using ${rubyVersion} as input from Gemfile.lock`) } let engine, version if (/^(\d+)/.test(rubyVersion) || common.isHeadVersion(rubyVersion)) { // X.Y.Z => ruby-X.Y.Z engine = 'ruby' version = rubyVersion + } else if (rubyVersion.includes(' ')) { // engine X.Y.Z + [engine, version] = common.partition(rubyVersion, ' ') } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion engine = rubyVersion version = '' // Let the logic in validateRubyEngineAndVersion() find the version @@ -137,6 +160,8 @@ function parseRubyEngineAndVersion(rubyVersion) { [engine, version] = common.partition(rubyVersion, '-') } + console.log(`Using ruby engine ${engine} and version ${version}`) + return [engine, version] } From b0bb5807e11a5e7baa079e2f814e2a1ed9de2cd0 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Mon, 6 May 2024 10:15:33 -0300 Subject: [PATCH 02/13] Suggested changes Co-authored-by: Benoit Daloze --- action.yml | 2 +- index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index c3fa4a568..acedd986d 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,7 @@ branding: icon: download inputs: ruby-version: - description: 'Engine and version to use, see the syntax in the README. Reads from .ruby-version, .tool-versions or Gemfile.lock.' + description: 'Engine and version to use, see the syntax in the README. When not set, it tries to read the version from .ruby-version, .tool-versions or Gemfile.lock.' default: 'default' rubygems: description: | diff --git a/index.js b/index.js index b00f963fe..0fdabf6d0 100644 --- a/index.js +++ b/index.js @@ -111,7 +111,7 @@ function readRubyVersionFromGemfileLock(lockFile) { const lines = contents.split(/\r?\n/) const rubyVersionLine = lines.findIndex(line => /^RUBY VERSION$/.test(line.trim())) if (rubyVersionLine !== -1) { - const nextLine = lines[rubyVersionLine+1].trim().replace(/p\d+$/, '') // Strip off patchlevel because ruby-builder can't be that precise + const nextLine = lines[rubyVersionLine+1].trim().replace(/p\d+$/, '') // Strip off patchlevel return nextLine } } @@ -127,7 +127,7 @@ function parseRubyEngineAndVersion(rubyVersion) { } else if (fs.existsSync('Gemfile.lock')) { rubyVersion = 'gemfile' } else { - throw new Error('input ruby-version needs to be specified if no .ruby-version, .tool-versions or Gemfile.lock file exists') + throw new Error('input ruby-version needs to be specified if there is no Ruby version in .ruby-version, .tool-versions or Gemfile.lock') } } From af0c90171fc2572200f0e97ff75340fed60040b3 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Mon, 6 May 2024 10:20:12 -0300 Subject: [PATCH 03/13] Unrelated upgrades --- .ruby-version | 2 +- .tool-versions | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.ruby-version b/.ruby-version index 4a85a55cf..d7edb5686 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-3.3.1 +ruby-2.6.5 diff --git a/.tool-versions b/.tool-versions index bfb55a217..fcae721d1 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,3 @@ nodejs 16.0.0 yarn 1.22.19 -ruby 3.3.1 +ruby 2.7.0 From a6d893d30b64515a3ff30375603659d28c62c5fe Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Mon, 6 May 2024 10:42:12 -0300 Subject: [PATCH 04/13] What if people manually edit Gemfile.lock? --- dist/index.js | 10 +++++++--- index.js | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index 6122c128d..d05626825 100644 --- a/dist/index.js +++ b/dist/index.js @@ -65850,8 +65850,12 @@ function readRubyVersionFromGemfileLock(lockFile) { const lines = contents.split(/\r?\n/) const rubyVersionLine = lines.findIndex(line => /^RUBY VERSION$/.test(line.trim())) if (rubyVersionLine !== -1) { - const nextLine = lines[rubyVersionLine+1].trim().replace(/p\d+$/, '') // Strip off patchlevel because ruby-builder can't be that precise - return nextLine + const nextLine = lines[bundledWithLine+1] + if (nextLine) { + const rubyVersion = nextLine.trim().replace(/p\d+$/, '') // Strip off patchlevel + console.log(`Using Ruby ${rubyVersion} from ${lockFile}`) + return rubyVersion + } } } return null @@ -65866,7 +65870,7 @@ function parseRubyEngineAndVersion(rubyVersion) { } else if (fs.existsSync('Gemfile.lock')) { rubyVersion = 'gemfile' } else { - throw new Error('input ruby-version needs to be specified if no .ruby-version, .tool-versions or Gemfile.lock file exists') + throw new Error('input ruby-version needs to be specified if there is no Ruby version in .ruby-version, .tool-versions or Gemfile.lock') } } diff --git a/index.js b/index.js index 0fdabf6d0..32fedd4be 100644 --- a/index.js +++ b/index.js @@ -111,8 +111,12 @@ function readRubyVersionFromGemfileLock(lockFile) { const lines = contents.split(/\r?\n/) const rubyVersionLine = lines.findIndex(line => /^RUBY VERSION$/.test(line.trim())) if (rubyVersionLine !== -1) { - const nextLine = lines[rubyVersionLine+1].trim().replace(/p\d+$/, '') // Strip off patchlevel - return nextLine + const nextLine = lines[bundledWithLine+1] + if (nextLine) { + const rubyVersion = nextLine.trim().replace(/p\d+$/, '') // Strip off patchlevel + console.log(`Using Ruby ${rubyVersion} from ${lockFile}`) + return rubyVersion + } } } return null From eaa7897dd1fb10ec359193aed785345aa948ba38 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Mon, 6 May 2024 11:41:54 -0300 Subject: [PATCH 05/13] Consistent errors --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 32fedd4be..0e5ccd298 100644 --- a/index.js +++ b/index.js @@ -146,7 +146,7 @@ function parseRubyEngineAndVersion(rubyVersion) { } else if (rubyVersion === 'gemfile') { // Read from Gemfile.lock rubyVersion = readRubyVersionFromGemfileLock('Gemfile.lock') if (rubyVersion === null) { - throw new Error('Could not find Ruby version in Gemfile.lock') + throw new Error('input ruby-version needs to be specified if there is no Ruby version in .ruby-version, .tool-versions or Gemfile.lock') } console.log(`Using ${rubyVersion} as input from Gemfile.lock`) } From dec9320d05d9ebf255eb16e11c41979f6fa00640 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Mon, 6 May 2024 12:12:55 -0300 Subject: [PATCH 06/13] Re-build --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index d05626825..beadabe59 100644 --- a/dist/index.js +++ b/dist/index.js @@ -65885,7 +65885,7 @@ function parseRubyEngineAndVersion(rubyVersion) { } else if (rubyVersion === 'gemfile') { // Read from Gemfile.lock rubyVersion = readRubyVersionFromGemfileLock('Gemfile.lock') if (rubyVersion === null) { - throw new Error('Could not find Ruby version in Gemfile.lock') + throw new Error('input ruby-version needs to be specified if there is no Ruby version in .ruby-version, .tool-versions or Gemfile.lock') } console.log(`Using ${rubyVersion} as input from Gemfile.lock`) } From 4952a54767a1854429aed881a42b88874a1b9b6f Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Mon, 6 May 2024 12:14:08 -0300 Subject: [PATCH 07/13] Putting back whitespace --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f8a37d869..3a2b64af5 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ This action currently supports these versions of MRI, JRuby and TruffleRuby: | `truffleruby` | 19.3.0 - 24.0.1, head | | `truffleruby+graalvm` | 21.2.0 - 24.0.1, head | -`ruby-debug` is the same as `ruby-head` but with assertions enabled (`-DRUBY_DEBUG=1`). +`ruby-debug` is the same as `ruby-head` but with assertions enabled (`-DRUBY_DEBUG=1`). Regarding Windows ruby master builds, `mingw` is a MSYS2/MinGW build, `head` & `ucrt` are MSYS2/UCRT64 builds, and `mswin` is a MSVC/VS 2022 build. @@ -177,8 +177,8 @@ This action provides a way to automatically run `bundle install` and cache the r Note that any step doing `bundle install` (for the root `Gemfile`) or `gem install bundler` can be removed with `bundler-cache: true`. -This caching speeds up installing gems significantly and avoids too many requests to RubyGems.org. -It needs a `Gemfile` (or `$BUNDLE_GEMFILE` or `gems.rb`) under the [`working-directory`](#working-directory). +This caching speeds up installing gems significantly and avoids too many requests to RubyGems.org. +It needs a `Gemfile` (or `$BUNDLE_GEMFILE` or `gems.rb`) under the [`working-directory`](#working-directory). If there is a `Gemfile.lock` (or `$BUNDLE_GEMFILE.lock` or `gems.locked`), `bundle config --local deployment true` is used. To use a `Gemfile` which is not at the root or has a different name, set `BUNDLE_GEMFILE` in the `env` at the job level @@ -192,7 +192,7 @@ They should be set in the `env` at the job level as shown in the [example](#matr To find the correct the environment variable name, see the [Bundler docs](https://bundler.io/man/bundle-config.1.html) or look at `.bundle/config` after running `bundle config --local KEY VALUE` locally. You might need to `"`-quote the environment variable name in YAML if it has unusual characters like `/`. -To perform caching, this action will use `bundle config --local path $PWD/vendor/bundle`. +To perform caching, this action will use `bundle config --local path $PWD/vendor/bundle`. Therefore, the Bundler `path` should not be changed in your workflow for the cache to work (no `bundle config path`). #### How it Works From 6b62e5d4ecc4895255756805f3d8c3c404c2a66e Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Mon, 6 May 2024 12:49:34 -0300 Subject: [PATCH 08/13] Handle alternative ruby engines in Gemfile.lock --- .github/workflows/test.yml | 12 ++++++++++++ dist/index.js | 9 ++++++--- gemfiles/ruby-version-engine.gemfile | 3 +++ gemfiles/ruby-version-engine.gemfile.lock | 14 ++++++++++++++ index.js | 9 ++++++--- 5 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 gemfiles/ruby-version-engine.gemfile create mode 100644 gemfiles/ruby-version-engine.gemfile.lock diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 25f2ad0e1..4b450326b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -229,6 +229,18 @@ jobs: ruby-version: gemfile - run: ruby --version | grep -F "3.3.1" + testRubyEngineVersionFromGemfile: + name: "Test RUBY VERSION from Gemfile.lock" + runs-on: ubuntu-latest + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/ruby-version-engine.gemfile + steps: + - uses: actions/checkout@v4 + - uses: ./ + with: + ruby-version: gemfile + - run: ruby --version | grep -F "truffleruby 24.0.1, like ruby 3.2.2" + testUseBundlerFromRubyGemsUpdate: name: "Test rubygems: version uses the Bundler installed by the rubygems update" runs-on: ubuntu-latest diff --git a/dist/index.js b/dist/index.js index beadabe59..098fafa47 100644 --- a/dist/index.js +++ b/dist/index.js @@ -65852,7 +65852,12 @@ function readRubyVersionFromGemfileLock(lockFile) { if (rubyVersionLine !== -1) { const nextLine = lines[bundledWithLine+1] if (nextLine) { - const rubyVersion = nextLine.trim().replace(/p\d+$/, '') // Strip off patchlevel + const versionLine = nextLine.trim() + if (versionLine.includes('(')) { // Alternative engine + const rubyVersion = versionLine.match(/\(([^)]+)\)/)[1].replace(' ', '-') + } else { + const rubyVersion = versionLine.replace(' ', '-').replace(/p\d+$/, '') // Strip off patchlevel + } console.log(`Using Ruby ${rubyVersion} from ${lockFile}`) return rubyVersion } @@ -65894,8 +65899,6 @@ function parseRubyEngineAndVersion(rubyVersion) { if (/^(\d+)/.test(rubyVersion) || common.isHeadVersion(rubyVersion)) { // X.Y.Z => ruby-X.Y.Z engine = 'ruby' version = rubyVersion - } else if (rubyVersion.includes(' ')) { // engine X.Y.Z - [engine, version] = common.partition(rubyVersion, ' ') } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion engine = rubyVersion version = '' // Let the logic in validateRubyEngineAndVersion() find the version diff --git a/gemfiles/ruby-version-engine.gemfile b/gemfiles/ruby-version-engine.gemfile new file mode 100644 index 000000000..cedb187ef --- /dev/null +++ b/gemfiles/ruby-version-engine.gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +ruby "3.2.2", engine: "truffleruby", engine_version: "24.0.1" diff --git a/gemfiles/ruby-version-engine.gemfile.lock b/gemfiles/ruby-version-engine.gemfile.lock new file mode 100644 index 000000000..cce346f6d --- /dev/null +++ b/gemfiles/ruby-version-engine.gemfile.lock @@ -0,0 +1,14 @@ +GEM + remote: https://rubygems.org/ + specs: + +PLATFORMS + aarch64-darwin + +DEPENDENCIES + +RUBY VERSION + ruby 3.2.2p0 (truffleruby 24.0.1) + +BUNDLED WITH + 2.4.10 diff --git a/index.js b/index.js index 0e5ccd298..5e500e816 100644 --- a/index.js +++ b/index.js @@ -113,7 +113,12 @@ function readRubyVersionFromGemfileLock(lockFile) { if (rubyVersionLine !== -1) { const nextLine = lines[bundledWithLine+1] if (nextLine) { - const rubyVersion = nextLine.trim().replace(/p\d+$/, '') // Strip off patchlevel + const versionLine = nextLine.trim() + if (versionLine.includes('(')) { // Alternative engine + const rubyVersion = versionLine.match(/\(([^)]+)\)/)[1].replace(' ', '-') + } else { + const rubyVersion = versionLine.replace(' ', '-').replace(/p\d+$/, '') // Strip off patchlevel + } console.log(`Using Ruby ${rubyVersion} from ${lockFile}`) return rubyVersion } @@ -155,8 +160,6 @@ function parseRubyEngineAndVersion(rubyVersion) { if (/^(\d+)/.test(rubyVersion) || common.isHeadVersion(rubyVersion)) { // X.Y.Z => ruby-X.Y.Z engine = 'ruby' version = rubyVersion - } else if (rubyVersion.includes(' ')) { // engine X.Y.Z - [engine, version] = common.partition(rubyVersion, ' ') } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion engine = rubyVersion version = '' // Let the logic in validateRubyEngineAndVersion() find the version From 603cf8daad5fb40add17df4d7dc0c9b667aa2877 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Mon, 6 May 2024 13:01:14 -0300 Subject: [PATCH 09/13] Typo --- dist/index.js | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 098fafa47..ffc744ddb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -65850,7 +65850,7 @@ function readRubyVersionFromGemfileLock(lockFile) { const lines = contents.split(/\r?\n/) const rubyVersionLine = lines.findIndex(line => /^RUBY VERSION$/.test(line.trim())) if (rubyVersionLine !== -1) { - const nextLine = lines[bundledWithLine+1] + const nextLine = lines[rubyVersionLine+1] if (nextLine) { const versionLine = nextLine.trim() if (versionLine.includes('(')) { // Alternative engine diff --git a/index.js b/index.js index 5e500e816..6a809dcff 100644 --- a/index.js +++ b/index.js @@ -111,7 +111,7 @@ function readRubyVersionFromGemfileLock(lockFile) { const lines = contents.split(/\r?\n/) const rubyVersionLine = lines.findIndex(line => /^RUBY VERSION$/.test(line.trim())) if (rubyVersionLine !== -1) { - const nextLine = lines[bundledWithLine+1] + const nextLine = lines[rubyVersionLine+1] if (nextLine) { const versionLine = nextLine.trim() if (versionLine.includes('(')) { // Alternative engine From b68bcd0374e56a02e090124d476207337564b3ab Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Mon, 6 May 2024 13:04:13 -0300 Subject: [PATCH 10/13] Scope --- dist/index.js | 8 ++++---- index.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index ffc744ddb..6dfb6e973 100644 --- a/dist/index.js +++ b/dist/index.js @@ -65845,6 +65845,7 @@ async function setupRuby(options = {}) { } function readRubyVersionFromGemfileLock(lockFile) { + const rubyVersion = null if (lockFile !== null && fs.existsSync(lockFile)) { const contents = fs.readFileSync(lockFile, 'utf8') const lines = contents.split(/\r?\n/) @@ -65854,16 +65855,15 @@ function readRubyVersionFromGemfileLock(lockFile) { if (nextLine) { const versionLine = nextLine.trim() if (versionLine.includes('(')) { // Alternative engine - const rubyVersion = versionLine.match(/\(([^)]+)\)/)[1].replace(' ', '-') + rubyVersion = versionLine.match(/\(([^)]+)\)/)[1].replace(' ', '-') } else { - const rubyVersion = versionLine.replace(' ', '-').replace(/p\d+$/, '') // Strip off patchlevel + rubyVersion = versionLine.replace(' ', '-').replace(/p\d+$/, '') // Strip off patchlevel } console.log(`Using Ruby ${rubyVersion} from ${lockFile}`) - return rubyVersion } } } - return null + return rubyVersion } function parseRubyEngineAndVersion(rubyVersion) { diff --git a/index.js b/index.js index 6a809dcff..09c71a225 100644 --- a/index.js +++ b/index.js @@ -106,6 +106,7 @@ export async function setupRuby(options = {}) { } function readRubyVersionFromGemfileLock(lockFile) { + const rubyVersion = null if (lockFile !== null && fs.existsSync(lockFile)) { const contents = fs.readFileSync(lockFile, 'utf8') const lines = contents.split(/\r?\n/) @@ -115,16 +116,15 @@ function readRubyVersionFromGemfileLock(lockFile) { if (nextLine) { const versionLine = nextLine.trim() if (versionLine.includes('(')) { // Alternative engine - const rubyVersion = versionLine.match(/\(([^)]+)\)/)[1].replace(' ', '-') + rubyVersion = versionLine.match(/\(([^)]+)\)/)[1].replace(' ', '-') } else { - const rubyVersion = versionLine.replace(' ', '-').replace(/p\d+$/, '') // Strip off patchlevel + rubyVersion = versionLine.replace(' ', '-').replace(/p\d+$/, '') // Strip off patchlevel } console.log(`Using Ruby ${rubyVersion} from ${lockFile}`) - return rubyVersion } } } - return null + return rubyVersion } function parseRubyEngineAndVersion(rubyVersion) { From 9083affda83f498a7d9997f51c79ce3820f302b7 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Mon, 6 May 2024 13:05:38 -0300 Subject: [PATCH 11/13] Typo --- dist/index.js | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 6dfb6e973..e8085f378 100644 --- a/dist/index.js +++ b/dist/index.js @@ -65845,7 +65845,7 @@ async function setupRuby(options = {}) { } function readRubyVersionFromGemfileLock(lockFile) { - const rubyVersion = null + let rubyVersion = null if (lockFile !== null && fs.existsSync(lockFile)) { const contents = fs.readFileSync(lockFile, 'utf8') const lines = contents.split(/\r?\n/) diff --git a/index.js b/index.js index 09c71a225..f3c60fddf 100644 --- a/index.js +++ b/index.js @@ -106,7 +106,7 @@ export async function setupRuby(options = {}) { } function readRubyVersionFromGemfileLock(lockFile) { - const rubyVersion = null + let rubyVersion = null if (lockFile !== null && fs.existsSync(lockFile)) { const contents = fs.readFileSync(lockFile, 'utf8') const lines = contents.split(/\r?\n/) From 39f23928c3af95a13fe190c28ca0139e5acf21cb Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Mon, 6 May 2024 13:19:15 -0300 Subject: [PATCH 12/13] Duplicate logging --- dist/index.js | 12 +++++------- index.js | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/dist/index.js b/dist/index.js index e8085f378..ee3eb0bb3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -65845,7 +65845,6 @@ async function setupRuby(options = {}) { } function readRubyVersionFromGemfileLock(lockFile) { - let rubyVersion = null if (lockFile !== null && fs.existsSync(lockFile)) { const contents = fs.readFileSync(lockFile, 'utf8') const lines = contents.split(/\r?\n/) @@ -65853,17 +65852,16 @@ function readRubyVersionFromGemfileLock(lockFile) { if (rubyVersionLine !== -1) { const nextLine = lines[rubyVersionLine+1] if (nextLine) { - const versionLine = nextLine.trim() - if (versionLine.includes('(')) { // Alternative engine - rubyVersion = versionLine.match(/\(([^)]+)\)/)[1].replace(' ', '-') + const rubyVersion = nextLine.trim() + if (rubyVersion.includes('(')) { // Alternative engine + return rubyVersion.match(/\(([^)]+)\)/)[1].replace(' ', '-') } else { - rubyVersion = versionLine.replace(' ', '-').replace(/p\d+$/, '') // Strip off patchlevel + return rubyVersion.replace(' ', '-').replace(/p\d+$/, '') // Strip off patchlevel } - console.log(`Using Ruby ${rubyVersion} from ${lockFile}`) } } } - return rubyVersion + return null } function parseRubyEngineAndVersion(rubyVersion) { diff --git a/index.js b/index.js index f3c60fddf..29221fd27 100644 --- a/index.js +++ b/index.js @@ -106,7 +106,6 @@ export async function setupRuby(options = {}) { } function readRubyVersionFromGemfileLock(lockFile) { - let rubyVersion = null if (lockFile !== null && fs.existsSync(lockFile)) { const contents = fs.readFileSync(lockFile, 'utf8') const lines = contents.split(/\r?\n/) @@ -114,17 +113,16 @@ function readRubyVersionFromGemfileLock(lockFile) { if (rubyVersionLine !== -1) { const nextLine = lines[rubyVersionLine+1] if (nextLine) { - const versionLine = nextLine.trim() - if (versionLine.includes('(')) { // Alternative engine - rubyVersion = versionLine.match(/\(([^)]+)\)/)[1].replace(' ', '-') + const rubyVersion = nextLine.trim() + if (rubyVersion.includes('(')) { // Alternative engine + return rubyVersion.match(/\(([^)]+)\)/)[1].replace(' ', '-') } else { - rubyVersion = versionLine.replace(' ', '-').replace(/p\d+$/, '') // Strip off patchlevel + return rubyVersion.replace(' ', '-').replace(/p\d+$/, '') // Strip off patchlevel } - console.log(`Using Ruby ${rubyVersion} from ${lockFile}`) } } } - return rubyVersion + return null } function parseRubyEngineAndVersion(rubyVersion) { From 13a2c2cf356a52f6b4c03f27d914659344c74d85 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Mon, 6 May 2024 14:20:04 -0300 Subject: [PATCH 13/13] This project's dependencies are unspecified --- .tool-versions | 1 - 1 file changed, 1 deletion(-) diff --git a/.tool-versions b/.tool-versions index fcae721d1..20e3745aa 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,2 @@ nodejs 16.0.0 -yarn 1.22.19 ruby 2.7.0