Skip to content

Commit

Permalink
Cleanup matching for .tool-versions and mise and add tests for .ruby-…
Browse files Browse the repository at this point in the history
…version and .tool-versions
  • Loading branch information
eregon committed Mar 11, 2025
1 parent 28233a0 commit 30755d8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}

Expand Down

0 comments on commit 30755d8

Please # to comment.