Skip to content

Commit 52bdd5b

Browse files
committed
Fixup Rubygems latest
1 parent df99e80 commit 52bdd5b

File tree

5 files changed

+71
-10
lines changed

5 files changed

+71
-10
lines changed

.github/workflows/test.yml

+13-3
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,25 @@ jobs:
169169
- run: ruby -v
170170

171171
testLatestRubygemsVersion:
172-
name: "Test rubygems: latest upgrades the default RubyGems version"
172+
name: "Ruby ${{ matrix.ruby }}: latest upgrades RubyGems"
173173
runs-on: ubuntu-latest
174+
strategy:
175+
fail-fast: false
176+
matrix:
177+
include:
178+
- { ruby: '3.2', expected_rubygems_version: '3.5.3' }
179+
- { ruby: '3.0', expected_rubygems_version: '3.5.3' }
180+
- { ruby: '2.7', expected_rubygems_version: '3.4.22' }
181+
- { ruby: '2.6', expected_rubygems_version: '3.4.22' }
182+
- { ruby: '2.5', expected_rubygems_version: '3.3.27' }
183+
- { ruby: '2.3', expected_rubygems_version: '3.3.27' }
174184
steps:
175185
- uses: actions/checkout@v4
176186
- uses: ./
177187
with:
178-
ruby-version: '2.6'
188+
ruby-version: ${{ matrix.ruby }}
179189
rubygems: latest
180-
- run: ruby -e "exit(Gem.rubygems_version > Gem::Version.new('3.0.3'))"
190+
- run: ruby -e 'puts Gem::VERSION; exit(Gem.rubygems_version >= Gem::Version.new("${{ matrix.expected_rubygems_version }}"))'
181191

182192
testFixedRubygemsVersionUpgrades:
183193
name: "Test rubygems: version upgrades RubyGems to that version if the default is older"

action.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ inputs:
1212
description: |
1313
The version of RubyGems to use. Either 'default' (the default), 'latest', or a version number (e.g., 3.3.5).
1414
For 'default', no action is taken and the version of RubyGems that comes with Ruby by default is used.
15-
For 'latest', `gem update --system` is run to update to the latest RubyGems version.
15+
For 'latest', `gem update --system` is run to update to the latest compatible RubyGems version.
16+
Ruby head/master builds and Ruby 2.2 and earlier will not be updated.
1617
Similarly, if a version number is given, `gem update --system <version>` is run to update to that version of RubyGems, as long as that version is newer than the one provided by default.
1718
bundler:
1819
description: |

dist/index.js

+28-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export async function setupRuby(options = {}) {
7878
const rubygemsInputSet = inputs['rubygems'] !== 'default'
7979
if (rubygemsInputSet) {
8080
await common.measure('Updating RubyGems', async () =>
81-
rubygems.rubygemsUpdate(inputs['rubygems'], rubyPrefix))
81+
rubygems.rubygemsUpdate(inputs['rubygems'], rubyPrefix, platform, engine, version))
8282
}
8383

8484
// When setup-ruby is used by other actions, this allows code in them to run

rubygems.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
const common = require('./common')
12
const path = require('path')
23
const exec = require('@actions/exec')
34
const semver = require('semver')
45

5-
export async function rubygemsUpdate(rubygemsVersionInput, rubyPrefix) {
6+
export async function rubygemsUpdate(rubygemsVersionInput, rubyPrefix, platform, engine, version) {
67
const gem = path.join(rubyPrefix, 'bin', 'gem')
78

89
let gemVersion = ''
@@ -18,7 +19,7 @@ export async function rubygemsUpdate(rubygemsVersionInput, rubyPrefix) {
1819

1920
if (rubygemsVersionInput === 'latest') {
2021
console.log('Updating RubyGems to latest version')
21-
await exec.exec(gem, ['update', '--system'])
22+
await rubygemsLatest(gem, platform, engine, version)
2223
} else if (semver.gt(rubygemsVersionInput, gemVersion)) {
2324
console.log(`Updating RubyGems to ${rubygemsVersionInput}`)
2425
await exec.exec(gem, ['update', '--system', rubygemsVersionInput])
@@ -28,3 +29,27 @@ export async function rubygemsUpdate(rubygemsVersionInput, rubyPrefix) {
2829

2930
return true
3031
}
32+
33+
// Older RubyGems versions do not account for 'required_ruby_version' when
34+
// running 'gem update --system', so we have to force a compatible version of
35+
// rubygems-update. See https://github.com/ruby/setup-ruby/pull/551 and
36+
// https://github.com/rubygems/rubygems/issues/7329
37+
async function rubygemsLatest(gem, platform, engine, version) {
38+
if (engine === 'ruby') {
39+
const version_float = common.floatVersion(version)
40+
if (common.isHeadVersion(version)) {
41+
console.log('Ruby master builds use included RubyGems')
42+
} else if (version_float >= common.floatVersion('3.0')) {
43+
await exec.exec(gem, ['update', '--system'])
44+
} else if (version_float >= common.floatVersion('2.6')) {
45+
await exec.exec(gem, ['update', '--system', '3.4.22'])
46+
} else if (version_float >= common.floatVersion('2.3')) {
47+
await exec.exec(gem, ['update', '--system', '3.3.27'])
48+
} else {
49+
console.log(`Cannot update RubyGems for Ruby version ${version}`)
50+
}
51+
} else {
52+
// non MRI Rubies (TruffleRuby and JRuby)
53+
await exec.exec(gem, ['update', '--system'])
54+
}
55+
}

0 commit comments

Comments
 (0)