forked from ruby/setup-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrubygems.js
30 lines (24 loc) · 1007 Bytes
/
rubygems.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
}