From c3f0cb18af43fef0f79b729c0487ff0dfa88dbcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 21 Jan 2022 08:55:27 +0100 Subject: [PATCH] Add a new input to optionally update RubyGems --- .github/workflows/test.yml | 22 ++++++++++++++++++++++ action.yml | 7 +++++++ dist/index.js | 30 ++++++++++++++++++++++++++++++ index.js | 7 +++++++ rubygems.js | 11 +++++++++++ 5 files changed, 77 insertions(+) create mode 100644 rubygems.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc4e14a..4d302d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/action.yml b/action.yml index 14732f8..23d1772 100644 --- a/action.yml +++ b/action.yml @@ -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 ` 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). diff --git a/dist/index.js b/dist/index.js index 56e93f8..9700cf5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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. diff --git a/index.js b/index.js index a94fa3c..419d718 100644 --- a/index.js +++ b/index.js @@ -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. diff --git a/rubygems.js b/rubygems.js new file mode 100644 index 0000000..105f61d --- /dev/null +++ b/rubygems.js @@ -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 +}