From e1a9bd158e61100e5d4e2e0fcd8468895d087b39 Mon Sep 17 00:00:00 2001 From: Masatoshi Iwasaki Date: Fri, 1 Nov 2019 21:03:45 +0900 Subject: [PATCH] Support ruby_version --- lib/setup-ruby.js | 13 +++++++++++++ src/setup-ruby.ts | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/setup-ruby.js b/lib/setup-ruby.js index acad2f49..a8960c27 100644 --- a/lib/setup-ruby.js +++ b/lib/setup-ruby.js @@ -16,14 +16,27 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(require("@actions/core")); +const exec = __importStar(require("@actions/exec")); const installer_1 = require("./installer"); function run() { return __awaiter(this, void 0, void 0, function* () { try { let version = core.getInput('version'); + if (!version) { + const options = {}; + // Ignore stderr because there is a fallback + // option to "ruby_version" parameter. + options.listeners = { + stdout: (data) => { + version += data.toString(); + } + }; + yield exec.exec('cat', ['.ruby-version'], options); + } if (!version) { version = core.getInput('ruby-version'); } + console.log(`ruby-version: ${version}`); yield installer_1.findRubyVersion(version); } catch (error) { diff --git a/src/setup-ruby.ts b/src/setup-ruby.ts index ddafe47a..a4a35895 100644 --- a/src/setup-ruby.ts +++ b/src/setup-ruby.ts @@ -1,12 +1,30 @@ import * as core from '@actions/core'; +import * as exec from '@actions/exec'; +import {ExecOptions} from '@actions/exec/lib/interfaces'; import {findRubyVersion} from './installer'; async function run() { try { let version = core.getInput('version'); + + if (!version) { + const options: ExecOptions = {}; + + // Ignore stderr because there is a fallback + // option to "ruby_version" parameter. + options.listeners = { + stdout: (data: Buffer) => { + version += data.toString(); + } + }; + + await exec.exec('cat', ['.ruby-version'], options); + } + if (!version) { version = core.getInput('ruby-version'); } + await findRubyVersion(version); } catch (error) { core.setFailed(error.message);