Skip to content

Add a new input to optionally update RubyGems #271

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

Merged
merged 5 commits into from
Jan 23, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,39 @@ jobs:
if: startsWith(matrix.os, 'windows') && startsWith(matrix.ruby, 'jruby')
run: gem install sassc

testLatestRubygemsVersion:
name: "Test rubygems input set to latest upgrades the default RubyGems version"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
ruby-version: 2.6
rubygems: latest
- run: ruby -e "exit(Gem.rubygems_version > Gem::Version.new('3.0.3'))"

testFixedRubygemsVersionUpgrades:
name: "Test rubygems input set to a fixed version upgrades RubyGems to that version if the default is older"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
ruby-version: 2.6
rubygems: 3.2.3
- run: gem --version | grep -F "3.2.3"

testFixedRubygemsVersionNoop:
name: "Test rubygems input set to a fixed version noops if the default is newer"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
ruby-version: 3.1
rubygems: 3.2.3
- run: gem --version | grep -F "3.3.3"

testExactBundlerVersion:
name: "Test with an exact Bundler version"
runs-on: ubuntu-latest
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ and the [condition and expression syntax](https://help.github.com/en/actions/ref
The `working-directory` input can be set to resolve `.ruby-version`, `.tool-versions` and `Gemfile.lock`
if they are not at the root of the repository, see [action.yml](action.yml) for details.

## RubyGems

By default, the default RubyGems version that comes with each Ruby is used.
However, users can optionally customize the RubyGems version that they want by
setting the `rubygems` input.

See [action.yml](action.yml) for more details about the `rubygems` input.

If you're running into `ArgumentError: wrong number of arguments (given 4,
expected 1)` errors with a stacktrace including Psych and RubyGems entries, you
should be able to fix them by setting `rubygems: 3.0.0` or higher.

### Bundler

By default, if there is a `Gemfile.lock` file (or `$BUNDLE_GEMFILE.lock` or `gems.locked`) with a `BUNDLED WITH` section,
Expand Down
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ inputs:
description: 'Engine and version to use, see the syntax in the README. Reads from .ruby-version or .tool-versions if unset.'
required: false
default: 'default'
rubygems:
description: |
The version of RubyGems to use. Either '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.
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.
Defaults to 'default'.
bundler:
description: |
The version of Bundler to install. Either 'none', 'latest', 'Gemfile.lock', or a version number (e.g., 1, 2, 2.1.4).
Expand Down
49 changes: 49 additions & 0 deletions dist/index.js

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

7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ const fs = require('fs')
const path = require('path')
const core = require('@actions/core')
const common = require('./common')
const rubygems = require('./rubygems')
const bundler = require('./bundler')

const windows = common.windows

const inputDefaults = {
'ruby-version': 'default',
'rubygems': 'default',
'bundler': 'default',
'bundler-cache': 'true',
'working-directory': '.',
Expand Down Expand Up @@ -60,6 +62,11 @@ export async function setupRuby(options = {}) {

const rubyPrefix = await installer.install(platform, engine, version)

if (inputs['rubygems'] !== 'default') {
await common.measure('Updating RubyGems', async () =>
rubygems.rubygemsUpdate(inputs['rubygems'], rubyPrefix))
}

// When setup-ruby is used by other actions, this allows code in them to run
// before 'bundle install'. Installed dependencies may require additional
// libraries & headers, build tools, etc.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"@actions/core": "^1.4.0",
"@actions/exec": "^1.1.0",
"@actions/io": "^1.1.1",
"@actions/tool-cache": "^1.7.1"
"@actions/tool-cache": "^1.7.1",
"semver": "^6.1.0"
},
"devDependencies": {
"@vercel/ncc": "^0.31.1"
Expand Down
30 changes: 30 additions & 0 deletions rubygems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const path = require('path')
const exec = require('@actions/exec')
const semver = require('semver')

export async function rubygemsUpdate(rubygemsVersionInput, rubyPrefix) {
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 exec.exec(gem, ['update', '--system'])
} 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
}