diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1db330f..5d2c967 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 cae2289..1762cf8 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 7ea9672..1bba0a4 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`) }