Compare commits

...
2 Commits
Author SHA1 Message Date
Benoit Daloze f964e8aa48 Try to find the Bundler version from Gemfile.lock, otherwise install latest 2020-04-01 00:10:54 +02:00
Benoit Daloze e16528e678 Test all Ruby minor versions
* Skip tests on the older ubuntu-16.04 to have a reasonable number of jobs
2020-04-01 00:10:54 +02:00
5 changed files with 111 additions and 17 deletions
+2 -2
View File
@@ -14,9 +14,9 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ ubuntu-16.04, ubuntu-18.04, macos-latest, windows-latest ] os: [ ubuntu-latest, macos-latest, windows-latest ]
# Use various version syntaxes here for testing # Use various version syntaxes here for testing
ruby: [ 2.2, 2.3, .ruby-version, .tool-versions, ruby-head, jruby-9.1, jruby, jruby-head, truffleruby, truffleruby-head ] ruby: [ 2.2, 2.3, 2.4, 2.5, 2.6.5, 2.7, ruby-head, jruby-9.1, jruby, jruby-head, truffleruby, truffleruby-head ]
exclude: exclude:
- os: windows-latest - os: windows-latest
ruby: truffleruby ruby: truffleruby
+5 -3
View File
@@ -105,9 +105,11 @@ jobs:
### Bundler ### Bundler
Currently, Bundler is guaranteed to be installed for all versions. By default, if there is a `Gemfile.lock` file with a `BUNDLED WITH` section,
If the Ruby ships with Bundler (Ruby >= 2.6), that version is used. the latest version of Bundler with the same major version will be installed.
Otherwise (Ruby < 2.6), Bundler 1 is installed when that Ruby was built. Otherwise, the latest Bundler version is installed (except for Ruby 2.2 where only Bundler 1 is supported).
This behavior can be customized, see [action.yml](action.yml) for details about the `bundler` input.
### Caching `bundle install` ### Caching `bundle install`
+4
View File
@@ -9,6 +9,10 @@ inputs:
description: 'Engine and version to use, see the syntax in the README. Reads from .ruby-version if unset.' description: 'Engine and version to use, see the syntax in the README. Reads from .ruby-version if unset.'
required: false required: false
default: 'default' default: 'default'
bundler:
description: 'The version of Bundler to install. Either none, 1, 2, latest or Gemfile.lock. The default tries Gemfile.lock and otherwise uses latest.'
required: false
default: 'default'
outputs: outputs:
ruby-prefix: ruby-prefix:
description: 'The prefix of the installed ruby' description: 'The prefix of the installed ruby'
Generated Vendored
+50 -6
View File
@@ -983,7 +983,7 @@ async function run() {
setupPath(ruby, newPathEntries) setupPath(ruby, newPathEntries)
await installBundler(platform, rubyPrefix) await installBundler(platform, rubyPrefix, engine, version)
core.setOutput('ruby-prefix', rubyPrefix) core.setOutput('ruby-prefix', rubyPrefix)
} catch (error) { } catch (error) {
@@ -1069,11 +1069,55 @@ function setupPath(ruby, newPathEntries) {
core.exportVariable('PATH', [...newPathEntries, ...cleanPath].join(path.delimiter)) core.exportVariable('PATH', [...newPathEntries, ...cleanPath].join(path.delimiter))
} }
async function installBundler(platform, rubyPrefix) { function readBundledWithFromGemfileLock() {
const bundle_exe = platform === 'windows-latest' ? 'bundle.cmd' : 'bundle' if (fs.existsSync('Gemfile.lock')) {
// Install Bundler if not already part of the stdlib const contents = fs.readFileSync('Gemfile.lock', 'utf8')
if (!fs.existsSync(path.join(rubyPrefix, 'bin', bundle_exe))) { const lines = contents.split(/\r?\n/)
await exec.exec(path.join(rubyPrefix, 'bin', 'gem'), ['install', 'bundler', '-v', '~> 1', '--no-document']) const bundledWithLine = lines.findIndex(line => /^BUNDLED WITH$/.test(line.trim()))
if (bundledWithLine !== -1) {
const nextLine = lines[bundledWithLine+1]
if (nextLine && /^\d+/.test(nextLine.trim())) {
const bundlerVersion = nextLine.trim()
const majorVersion = bundlerVersion.match(/^\d+/)[0]
console.log(`Using Bundler ${majorVersion} from Gemfile.lock BUNDLED WITH ${bundlerVersion}`)
return majorVersion
}
}
}
return null
}
async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
var bundlerVersion = core.getInput('bundler')
if (bundlerVersion === 'none') {
return
}
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
bundlerVersion = readBundledWithFromGemfileLock()
if (!bundlerVersion) {
bundlerVersion = 'latest'
}
}
let versionArray
if (rubyVersion.startsWith('2.2')) {
console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby 2.2')
versionArray = ['-v', '~> 1']
} else if (/^\d+/.test(bundlerVersion)) {
versionArray = ['-v', `~> ${bundlerVersion}`]
} else if (bundlerVersion === 'latest') {
versionArray = []
} else {
throw new Error(`Cannot parse bundler input: ${bundlerVersion}`)
}
if (engine === 'rubinius') {
console.log(`Rubinius only supports the version of Bundler shipped with it`)
} else if (bundlerVersion === '1' && engine === 'truffleruby') {
console.log(`Using the Bundler version shipped with ${engine}`)
} else {
await exec.exec(path.join(rubyPrefix, 'bin', 'gem'), ['install', 'bundler', ...versionArray, '--no-document'])
} }
} }
+50 -6
View File
@@ -25,7 +25,7 @@ export async function run() {
setupPath(ruby, newPathEntries) setupPath(ruby, newPathEntries)
await installBundler(platform, rubyPrefix) await installBundler(platform, rubyPrefix, engine, version)
core.setOutput('ruby-prefix', rubyPrefix) core.setOutput('ruby-prefix', rubyPrefix)
} catch (error) { } catch (error) {
@@ -111,11 +111,55 @@ function setupPath(ruby, newPathEntries) {
core.exportVariable('PATH', [...newPathEntries, ...cleanPath].join(path.delimiter)) core.exportVariable('PATH', [...newPathEntries, ...cleanPath].join(path.delimiter))
} }
async function installBundler(platform, rubyPrefix) { function readBundledWithFromGemfileLock() {
const bundle_exe = platform === 'windows-latest' ? 'bundle.cmd' : 'bundle' if (fs.existsSync('Gemfile.lock')) {
// Install Bundler if not already part of the stdlib const contents = fs.readFileSync('Gemfile.lock', 'utf8')
if (!fs.existsSync(path.join(rubyPrefix, 'bin', bundle_exe))) { const lines = contents.split(/\r?\n/)
await exec.exec(path.join(rubyPrefix, 'bin', 'gem'), ['install', 'bundler', '-v', '~> 1', '--no-document']) const bundledWithLine = lines.findIndex(line => /^BUNDLED WITH$/.test(line.trim()))
if (bundledWithLine !== -1) {
const nextLine = lines[bundledWithLine+1]
if (nextLine && /^\d+/.test(nextLine.trim())) {
const bundlerVersion = nextLine.trim()
const majorVersion = bundlerVersion.match(/^\d+/)[0]
console.log(`Using Bundler ${majorVersion} from Gemfile.lock BUNDLED WITH ${bundlerVersion}`)
return majorVersion
}
}
}
return null
}
async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
var bundlerVersion = core.getInput('bundler')
if (bundlerVersion === 'none') {
return
}
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
bundlerVersion = readBundledWithFromGemfileLock()
if (!bundlerVersion) {
bundlerVersion = 'latest'
}
}
let versionArray
if (rubyVersion.startsWith('2.2')) {
console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby 2.2')
versionArray = ['-v', '~> 1']
} else if (/^\d+/.test(bundlerVersion)) {
versionArray = ['-v', `~> ${bundlerVersion}`]
} else if (bundlerVersion === 'latest') {
versionArray = []
} else {
throw new Error(`Cannot parse bundler input: ${bundlerVersion}`)
}
if (engine === 'rubinius') {
console.log(`Rubinius only supports the version of Bundler shipped with it`)
} else if (bundlerVersion === '1' && engine === 'truffleruby') {
console.log(`Using the Bundler version shipped with ${engine}`)
} else {
await exec.exec(path.join(rubyPrefix, 'bin', 'gem'), ['install', 'bundler', ...versionArray, '--no-document'])
} }
} }