Skip to content

Commit

Permalink
Fixup Rubygems latest
Browse files Browse the repository at this point in the history
  • Loading branch information
MSP-Greg authored and eregon committed Dec 27, 2023
1 parent df99e80 commit 28f9302
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 10 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,25 @@ jobs:
- run: ruby -v

testLatestRubygemsVersion:
name: "Test rubygems: latest upgrades the default RubyGems version"
name: "Ruby ${{ matrix.ruby }}: latest upgrades RubyGems"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- { ruby: '3.2', expected_rubygems_version: '3.5.3' }
- { ruby: '3.0', expected_rubygems_version: '3.5.3' }
- { ruby: '2.7', expected_rubygems_version: '3.4.22' }
- { ruby: '2.6', expected_rubygems_version: '3.4.22' }
- { ruby: '2.5', expected_rubygems_version: '3.3.27' }
- { ruby: '2.3', expected_rubygems_version: '3.3.27' }
steps:
- uses: actions/checkout@v4
- uses: ./
with:
ruby-version: '2.6'
ruby-version: ${{ matrix.ruby }}
rubygems: latest
- run: ruby -e "exit(Gem.rubygems_version > Gem::Version.new('3.0.3'))"
- run: ruby -e 'puts Gem::VERSION; exit(Gem.rubygems_version >= Gem::Version.new("${{ matrix.expected_rubygems_version }}"))'

testFixedRubygemsVersionUpgrades:
name: "Test rubygems: version upgrades RubyGems to that version if the default is older"
Expand Down
3 changes: 2 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ inputs:
description: |
The version of RubyGems to use. Either 'default' (the default), 'latest', or a version number (e.g., 3.3.5).
For 'default', no action is taken and the version of RubyGems that comes with Ruby by default is used.
For 'latest', `gem update --system` is run to update to the latest RubyGems version.
For 'latest', `gem update --system` is run to update to the latest compatible RubyGems version.
Ruby head/master builds and Ruby 2.2 and earlier will not be updated.
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.
bundler:
description: |
Expand Down
31 changes: 28 additions & 3 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function setupRuby(options = {}) {
const rubygemsInputSet = inputs['rubygems'] !== 'default'
if (rubygemsInputSet) {
await common.measure('Updating RubyGems', async () =>
rubygems.rubygemsUpdate(inputs['rubygems'], rubyPrefix))
rubygems.rubygemsUpdate(inputs['rubygems'], rubyPrefix, platform, engine, version))
}

// When setup-ruby is used by other actions, this allows code in them to run
Expand Down
29 changes: 27 additions & 2 deletions rubygems.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const common = require('./common')
const path = require('path')
const exec = require('@actions/exec')
const semver = require('semver')

export async function rubygemsUpdate(rubygemsVersionInput, rubyPrefix) {
export async function rubygemsUpdate(rubygemsVersionInput, rubyPrefix, platform, engine, version) {
const gem = path.join(rubyPrefix, 'bin', 'gem')

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

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

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, version) {
if (engine === 'ruby') {
const rubyFloatVersion = common.floatVersion(version)
if (common.isHeadVersion(version)) {
console.log('Ruby master builds use included RubyGems')
} else if (rubyFloatVersion >= 3.0) {
await exec.exec(gem, ['update', '--system'])
} else if (rubyFloatVersion >= 2.6) {
await exec.exec(gem, ['update', '--system', '3.4.22'])
} else if (rubyFloatVersion >= 2.3) {
await exec.exec(gem, ['update', '--system', '3.3.27'])
} else {
console.log(`Cannot update RubyGems for Ruby version ${version}`)
}
} else {
// non MRI Rubies (TruffleRuby and JRuby)
await exec.exec(gem, ['update', '--system'])
}
}

0 comments on commit 28f9302

Please sign in to comment.