Skip to content

Ruby version should be read from Gemfile.lock by default #590

Closed
@benlangfeld

Description

@benlangfeld

Similarly to #38, the version of Ruby to be installed can be specified in Gemfile.lock via RUBY VERSION directive. This should be used the same way .ruby-version and .tool-versions are, for applications which lock their Ruby version using the Gemfile.lock, so as to avoid duplication and possible divergence.

Note to self, relevant functions:

  • setup-ruby/index.js

    Lines 108 to 141 in 1198b07

    function parseRubyEngineAndVersion(rubyVersion) {
    if (rubyVersion === 'default') {
    if (fs.existsSync('.ruby-version')) {
    rubyVersion = '.ruby-version'
    } else if (fs.existsSync('.tool-versions')) {
    rubyVersion = '.tool-versions'
    } else {
    throw new Error('input ruby-version needs to be specified if no .ruby-version or .tool-versions file exists')
    }
    }
    if (rubyVersion === '.ruby-version') { // Read from .ruby-version
    rubyVersion = fs.readFileSync('.ruby-version', 'utf8').trim()
    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.match(/^ruby\s+(.+)$/)[1]
    console.log(`Using ${rubyVersion} as input from file .tool-versions`)
    }
    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('-')) { // myruby -> myruby-stableVersion
    engine = rubyVersion
    version = '' // Let the logic in validateRubyEngineAndVersion() find the version
    } else { // engine-X.Y.Z
    [engine, version] = common.partition(rubyVersion, '-')
    }
    return [engine, version]
    }
  • setup-ruby/bundler.js

    Lines 30 to 49 in 1198b07

    function readBundledWithFromGemfileLock(lockFile) {
    if (lockFile !== null && fs.existsSync(lockFile)) {
    const contents = fs.readFileSync(lockFile, 'utf8')
    const lines = contents.split(/\r?\n/)
    const bundledWithLine = lines.findIndex(line => /^BUNDLED WITH$/.test(line.trim()))
    if (bundledWithLine !== -1) {
    const nextLine = lines[bundledWithLine+1]
    if (nextLine) {
    const bundlerVersion = nextLine.trim()
    if (isValidBundlerVersion(bundlerVersion)) {
    console.log(`Using Bundler ${bundlerVersion} from ${lockFile} BUNDLED WITH ${bundlerVersion}`)
    return bundlerVersion
    } else {
    console.log(`Could not parse BUNDLED WITH version as a valid Bundler release, ignoring it: ${bundlerVersion}`)
    }
    }
    }
    }
    return null
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions