Skip to content

Commit c3f0cb1

Browse files
deivid-rodriguezeregon
authored andcommitted
Add a new input to optionally update RubyGems
1 parent 180e1d1 commit c3f0cb1

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

.github/workflows/test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,28 @@ jobs:
112112
if: startsWith(matrix.os, 'windows') && startsWith(matrix.ruby, 'jruby')
113113
run: gem install sassc
114114

115+
testLatestRubygemsVersion:
116+
name: "Test rubygems input set to latest upgrades the default RubyGems version"
117+
runs-on: ubuntu-latest
118+
steps:
119+
- uses: actions/checkout@v2
120+
- uses: ./
121+
with:
122+
ruby-version: 2.6
123+
rubygems: latest
124+
- run: ruby -e "exit(Gem.rubygems_version > Gem::Version.new('3.0.3'))"
125+
126+
testFixedRubygemsVersion:
127+
name: "Test rubygems input set to a fixed version upgrades RubyGems to that versoin"
128+
runs-on: ubuntu-latest
129+
steps:
130+
- uses: actions/checkout@v2
131+
- uses: ./
132+
with:
133+
ruby-version: 2.6
134+
rubygems: 3.3.5
135+
- run: gem --version | grep -F "3.3.5"
136+
115137
testExactBundlerVersion:
116138
name: "Test with an exact Bundler version"
117139
runs-on: ubuntu-latest

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ inputs:
99
description: 'Engine and version to use, see the syntax in the README. Reads from .ruby-version or .tool-versions if unset.'
1010
required: false
1111
default: 'default'
12+
rubygems:
13+
description: |
14+
The version of RubyGems to use. Either 'default', 'latest', or a version number (e.g., 3.3.5).
15+
For 'default', no action is taken and the version of RubyGems that comes with Ruby by default is used.
16+
For 'latest', `gem update --system` is run to update to the latest RubyGems version.
17+
Similarly, if a version number is given, `gem update --system <version>` is run to update to that version of RubyGems.
18+
Defaults to 'default'.
1219
bundler:
1320
description: |
1421
The version of Bundler to install. Either 'none', 'latest', 'Gemfile.lock', or a version number (e.g., 1, 2, 2.1.4).

dist/index.js

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ const fs = require('fs')
33
const path = require('path')
44
const core = require('@actions/core')
55
const common = require('./common')
6+
const rubygems = require('./rubygems')
67
const bundler = require('./bundler')
78

89
const windows = common.windows
910

1011
const inputDefaults = {
1112
'ruby-version': 'default',
13+
'rubygems': 'default',
1214
'bundler': 'default',
1315
'bundler-cache': 'true',
1416
'working-directory': '.',
@@ -60,6 +62,11 @@ export async function setupRuby(options = {}) {
6062

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

65+
if (inputs['rubygems'] !== 'default') {
66+
await common.measure('Updating RubyGems', async () =>
67+
rubygems.rubygemsUpdate(inputs['rubygems'], rubyPrefix))
68+
}
69+
6370
// When setup-ruby is used by other actions, this allows code in them to run
6471
// before 'bundle install'. Installed dependencies may require additional
6572
// libraries & headers, build tools, etc.

rubygems.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const path = require('path')
2+
const exec = require('@actions/exec')
3+
4+
export async function rubygemsUpdate(rubygemsVersionInput, rubyPrefix) {
5+
const gem = path.join(rubyPrefix, 'bin', 'gem')
6+
const rubygemsVersion = (rubygemsVersionInput === 'latest') ? [] : [rubygemsVersionInput]
7+
8+
await exec.exec(gem, ['update', '--system', ...rubygemsVersion])
9+
10+
return true
11+
}

0 commit comments

Comments
 (0)