mirror of
https://github.com/ruby/setup-ruby.git
synced 2026-09-13 22:44:20 +02:00
If set up `rubygems: latest` in workflow, it will cause the error with Ruby 3.0 because the latest rubygems does not support Ruby 3.0. Ref. https://rubygems.org/gems/rubygems-update ### Error message ``` Updating RubyGems /opt/hostedtoolcache/Ruby/3.0.7/x64/bin/gem --version 3.2.33 Default RubyGems version is 3.2.33 Updating RubyGems to latest version /opt/hostedtoolcache/Ruby/3.0.7/x64/bin/gem update --system ERROR: Error installing rubygems-update: rubygems-update-3.6.1 requires Ruby version >= 3.1.0. The current ruby version is 3.0.7.220. ERROR: While executing gem ... (NoMethodError) undefined method `version' for nil:NilClass Updating rubygems-update Took 2.86 seconds Error: The process '/opt/hostedtoolcache/Ruby/3.0.7/x64/bin/gem' failed with exit code 1 ``` ### How to reproduce ``` uses: ruby/setup-ruby@v1 with: ruby-version: "3.0" rubygems: latest ```
61 lines
2.3 KiB
JavaScript
61 lines
2.3 KiB
JavaScript
const common = require('./common')
|
|
const path = require('path')
|
|
const exec = require('@actions/exec')
|
|
const semver = require('semver')
|
|
|
|
export async function rubygemsUpdate(rubygemsVersionInput, rubyPrefix, platform, engine, rubyVersion) {
|
|
const gem = path.join(rubyPrefix, 'bin', 'gem')
|
|
|
|
let gemVersion = ''
|
|
|
|
await exec.exec(gem, ['--version'], {
|
|
listeners: {
|
|
stdout: (data) => (gemVersion += data.toString()),
|
|
}
|
|
});
|
|
|
|
gemVersion = semver.coerce(gemVersion.trim())
|
|
console.log(`Default RubyGems version is ${gemVersion}`)
|
|
|
|
if (rubygemsVersionInput === 'latest') {
|
|
console.log('Updating RubyGems to latest version')
|
|
await rubygemsLatest(gem, platform, engine, rubyVersion)
|
|
} else if (semver.gt(rubygemsVersionInput, gemVersion)) {
|
|
console.log(`Updating RubyGems to ${rubygemsVersionInput}`)
|
|
await exec.exec(gem, ['update', '--system', rubygemsVersionInput])
|
|
} else {
|
|
console.log(`Skipping RubyGems update because the given version (${rubygemsVersionInput}) is not newer than the default version (${gemVersion})`)
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// Older RubyGems versions do not account for 'required_ruby_version' when
|
|
// running 'gem update --system', so we have to force a compatible version of
|
|
// rubygems-update. See https://github.com/ruby/setup-ruby/pull/551 and
|
|
// https://github.com/rubygems/rubygems/issues/7329
|
|
async function rubygemsLatest(gem, platform, engine, rubyVersion) {
|
|
if (engine === 'ruby') {
|
|
const floatVersion = common.floatVersion(rubyVersion)
|
|
if (common.isHeadVersion(rubyVersion)) {
|
|
console.log('Ruby master builds use included RubyGems')
|
|
} else if (floatVersion >= 3.1) {
|
|
await exec.exec(gem, ['update', '--system'])
|
|
} else if (floatVersion >= 3.0) {
|
|
await exec.exec(gem, ['update', '--system', '3.5.23'])
|
|
} else if (floatVersion >= 2.6) {
|
|
await exec.exec(gem, ['update', '--system', '3.4.22'])
|
|
} else if (floatVersion >= 2.3) {
|
|
await exec.exec(gem, ['update', '--system', '3.3.27'])
|
|
} else if (floatVersion >= 1.9) {
|
|
await exec.exec(`${gem} install rubygems-update -v 2.7.11 --no-document`)
|
|
await exec.exec('update_rubygems')
|
|
} else {
|
|
console.log(`Cannot update RubyGems for Ruby version ${rubyVersion}`)
|
|
}
|
|
} else {
|
|
// non MRI Rubies (TruffleRuby and JRuby)
|
|
await exec.exec(gem, ['update', '--system'])
|
|
}
|
|
}
|