Skip to content

Commit 8781aa9

Browse files
deivid-rodriguezeregon
authored andcommitted
Tweak rubygems input behavior
When a fixed version is passed, it should be the minimum RubyGems version for the whole matrix, i.e., RubyGems should not be dowgraded past the default version of the oldest Ruby in the matrix.
1 parent 578365d commit 8781aa9

File tree

5 files changed

+60
-10
lines changed

5 files changed

+60
-10
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,27 @@ jobs:
123123
rubygems: latest
124124
- run: ruby -e "exit(Gem.rubygems_version > Gem::Version.new('3.0.3'))"
125125

126-
testFixedRubygemsVersion:
127-
name: "Test rubygems input set to a fixed version upgrades RubyGems to that versoin"
126+
testFixedRubygemsVersionUpgrades:
127+
name: "Test rubygems input set to a fixed version upgrades RubyGems to that version if the default is older"
128128
runs-on: ubuntu-latest
129129
steps:
130130
- uses: actions/checkout@v2
131131
- uses: ./
132132
with:
133133
ruby-version: 2.6
134-
rubygems: 3.3.5
135-
- run: gem --version | grep -F "3.3.5"
134+
rubygems: 3.2.3
135+
- run: gem --version | grep -F "3.2.3"
136+
137+
testFixedRubygemsVersionNoop:
138+
name: "Test rubygems input set to a fixed version noops if the default is newer"
139+
runs-on: ubuntu-latest
140+
steps:
141+
- uses: actions/checkout@v2
142+
- uses: ./
143+
with:
144+
ruby-version: 3.1
145+
rubygems: 3.2.3
146+
- run: gem --version | grep -F "3.3.3"
136147

137148
testExactBundlerVersion:
138149
name: "Test with an exact Bundler version"

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ inputs:
1414
The version of RubyGems to use. Either 'default', 'latest', or a version number (e.g., 3.3.5).
1515
For 'default', no action is taken and the version of RubyGems that comes with Ruby by default is used.
1616
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.
17+
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.
1818
Defaults to 'default'.
1919
bundler:
2020
description: |

dist/index.js

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"@actions/core": "^1.4.0",
2727
"@actions/exec": "^1.1.0",
2828
"@actions/io": "^1.1.1",
29-
"@actions/tool-cache": "^1.7.1"
29+
"@actions/tool-cache": "^1.7.1",
30+
"semver": "^6.1.0"
3031
},
3132
"devDependencies": {
3233
"@vercel/ncc": "^0.31.1"

rubygems.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
const path = require('path')
22
const exec = require('@actions/exec')
3+
const semver = require('semver')
34

45
export async function rubygemsUpdate(rubygemsVersionInput, rubyPrefix) {
56
const gem = path.join(rubyPrefix, 'bin', 'gem')
6-
const rubygemsVersion = (rubygemsVersionInput === 'latest') ? [] : [rubygemsVersionInput]
77

8-
await exec.exec(gem, ['update', '--system', ...rubygemsVersion])
8+
let gemVersion = ''
9+
10+
await exec.exec(gem, ['--version'], {
11+
listeners: {
12+
stdout: (data) => (gemVersion += data.toString()),
13+
}
14+
});
15+
16+
gemVersion = semver.coerce(gemVersion.trim())
17+
console.log(`Default RubyGems version is ${gemVersion}`)
18+
19+
if (rubygemsVersionInput === 'latest') {
20+
console.log('Updating RubyGems to latest version')
21+
await exec.exec(gem, ['update', '--system'])
22+
} else if (semver.gt(rubygemsVersionInput, gemVersion)) {
23+
console.log(`Updating RubyGems to ${rubygemsVersionInput}`)
24+
await exec.exec(gem, ['update', '--system', rubygemsVersionInput])
25+
} else {
26+
console.log(`Skipping RubyGems update because the given version (${rubygemsVersionInput}) is not newer than the default version (${gemVersion})`)
27+
}
928

1029
return true
1130
}

0 commit comments

Comments
 (0)