Add a new input to optionally update RubyGems

This commit is contained in:
David Rodríguez
2022-01-23 11:55:32 +01:00
committed by Benoit Daloze
parent 180e1d1f1c
commit c3f0cb18af
5 changed files with 77 additions and 0 deletions
+22
View File
@@ -112,6 +112,28 @@ 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'))"
testFixedRubygemsVersion:
name: "Test rubygems input set to a fixed version upgrades RubyGems to that versoin"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
ruby-version: 2.6
rubygems: 3.3.5
- run: gem --version | grep -F "3.3.5"
testExactBundlerVersion:
name: "Test with an exact Bundler version"
runs-on: ubuntu-latest
+7
View File
@@ -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.
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).
Generated Vendored
+30
View File
@@ -58953,6 +58953,29 @@ function getLatestHeadBuildURL(platform, engine, version) {
}
/***/ }),
/***/ 160:
/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {
"use strict";
__nccwpck_require__.r(__webpack_exports__);
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
/* harmony export */ "rubygemsUpdate": () => (/* binding */ rubygemsUpdate)
/* harmony export */ });
const path = __nccwpck_require__(5622)
const exec = __nccwpck_require__(1514)
async function rubygemsUpdate(rubygemsVersionInput, rubyPrefix) {
const gem = path.join(rubyPrefix, 'bin', 'gem')
const rubygemsVersion = (rubygemsVersionInput === 'latest') ? [] : [rubygemsVersionInput]
await exec.exec(gem, ['update', '--system', ...rubygemsVersion])
return true
}
/***/ }),
/***/ 7223:
@@ -59566,12 +59589,14 @@ const fs = __nccwpck_require__(5747)
const path = __nccwpck_require__(5622)
const core = __nccwpck_require__(2186)
const common = __nccwpck_require__(4717)
const rubygems = __nccwpck_require__(160)
const bundler = __nccwpck_require__(1641)
const windows = common.windows
const inputDefaults = {
'ruby-version': 'default',
'rubygems': 'default',
'bundler': 'default',
'bundler-cache': 'true',
'working-directory': '.',
@@ -59623,6 +59648,11 @@ 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.
+7
View File
@@ -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': '.',
@@ -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.
+11
View File
@@ -0,0 +1,11 @@
const path = require('path')
const exec = require('@actions/exec')
export async function rubygemsUpdate(rubygemsVersionInput, rubyPrefix) {
const gem = path.join(rubyPrefix, 'bin', 'gem')
const rubygemsVersion = (rubygemsVersionInput === 'latest') ? [] : [rubygemsVersionInput]
await exec.exec(gem, ['update', '--system', ...rubygemsVersion])
return true
}