From 30755d8bf4ebfa38caa5ad3a6b808846393196a5 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Tue, 11 Mar 2025 12:08:21 +0100 Subject: [PATCH] Cleanup matching for .tool-versions and mise and add tests for .ruby-version and .tool-versions --- .github/workflows/test.yml | 27 +++++++++++++++++++++++++++ dist/index.js | 10 ++++++---- index.js | 10 ++++++---- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1db330ffc..5d2c967c1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -190,6 +190,33 @@ jobs: if: startsWith(matrix.os, 'windows') && matrix.ruby == 'jruby' run: gem install sassc + testDotRubyVersion: + name: "Test .ruby-version" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: echo "ruby-3.4.0" > .ruby-version + - uses: ./ + - run: ruby -v | grep -F "ruby 3.4.0" + + testToolVersions: + name: "Test .tool-versions" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: echo "nodejs 16.0.0\nruby 3.4.0" > .tool-versions + - uses: ./ + - run: ruby -v | grep -F "ruby 3.4.0" + + testMise: + name: "Test mise.toml" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: echo "[tools]\nnode = '18'\nruby = '3.4.0'" > mise.toml + - uses: ./ + - run: ruby -v | grep -F "ruby 3.4.0" + testNoGemfile: name: "Test with no Gemfile" runs-on: ubuntu-latest diff --git a/dist/index.js b/dist/index.js index cae2289f2..1762cf830 100644 --- a/dist/index.js +++ b/dist/index.js @@ -74932,13 +74932,15 @@ function parseRubyEngineAndVersion(rubyVersion) { console.log(`Using ${rubyVersion} as input from file .ruby-version`) } else if (rubyVersion === '.tool-versions') { // Read from .tool-versions const toolVersions = fs.readFileSync('.tool-versions', 'utf8').trim() - const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s/.test(e))[0] - rubyVersion = rubyLine.split(/\s+/)[1] + const regexp = /^ruby\s+(\S+)/ + const rubyLine = toolVersions.split(/\r?\n/).filter(e => regexp.test(e))[0] + rubyVersion = rubyLine.match(regexp)[1] console.log(`Using ${rubyVersion} as input from file .tool-versions`) } else if (rubyVersion === 'mise.toml') { // Read from mise.toml const toolVersions = fs.readFileSync('mise.toml', 'utf8').trim() - const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s*=\s*/.test(e))[0] - rubyVersion = rubyLine.match(/^ruby\s*=\s*['"](.+)['"]$/)[1] + const regexp = /^ruby\s*=\s*['"](.+)['"]$/ + const rubyLine = toolVersions.split(/\r?\n/).filter(e => regexp.test(e))[0] + rubyVersion = rubyLine.match(regexp)[1] console.log(`Using ${rubyVersion} as input from file mise.toml`) } diff --git a/index.js b/index.js index 7ea9672b0..1bba0a4be 100644 --- a/index.js +++ b/index.js @@ -129,13 +129,15 @@ function parseRubyEngineAndVersion(rubyVersion) { console.log(`Using ${rubyVersion} as input from file .ruby-version`) } else if (rubyVersion === '.tool-versions') { // Read from .tool-versions const toolVersions = fs.readFileSync('.tool-versions', 'utf8').trim() - const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s/.test(e))[0] - rubyVersion = rubyLine.split(/\s+/)[1] + const regexp = /^ruby\s+(\S+)/ + const rubyLine = toolVersions.split(/\r?\n/).filter(e => regexp.test(e))[0] + rubyVersion = rubyLine.match(regexp)[1] console.log(`Using ${rubyVersion} as input from file .tool-versions`) } else if (rubyVersion === 'mise.toml') { // Read from mise.toml const toolVersions = fs.readFileSync('mise.toml', 'utf8').trim() - const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s*=\s*/.test(e))[0] - rubyVersion = rubyLine.match(/^ruby\s*=\s*['"](.+)['"]$/)[1] + const regexp = /^ruby\s*=\s*['"](.+)['"]$/ + const rubyLine = toolVersions.split(/\r?\n/).filter(e => regexp.test(e))[0] + rubyVersion = rubyLine.match(regexp)[1] console.log(`Using ${rubyVersion} as input from file mise.toml`) }