Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup 'rubygems: latest' #551

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a link here to rubygems/rubygems#7329 or another appropriate issue explaining why we need to workaround this bug in RubyGems?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned, this has always been an issue, but since it's only tested here on Ruby 2.6, it failed because of the recently changed minimum Ruby version in RubyGems.

RubyGems 3.4 supported Ruby 2.6 and later, RubyGems 3.5 supports Ruby 3.0 and later.

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'])
}
}