Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Ruby version from Gemfile.lock #592

Closed
Prev Previous commit
Next Next commit
Duplicate logging
benlangfeld committed May 6, 2024
commit 39f23928c3af95a13fe190c28ca0139e5acf21cb
12 changes: 5 additions & 7 deletions dist/index.js

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

12 changes: 5 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -106,25 +106,23 @@ 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/)
const rubyVersionLine = lines.findIndex(line => /^RUBY VERSION$/.test(line.trim()))
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) {