From c8a88df1573f0fb5ee0390a60688742fd9846913 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sun, 14 Jun 2020 16:43:30 +0200 Subject: [PATCH] Refactor how to call setup-ruby from other actions * Automatically use inputs if available, use defaults otherwise. --- dist/index.js | 15 +++++++++------ index.js | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3fd8830..9147884 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2199,20 +2199,23 @@ const inputDefaults = { 'working-directory': '.', } +// entry point when this action is run on its own async function run() { try { - const options = {} - for (const key in inputDefaults) { - options[key] = core.getInput(key) - } - await setupRuby(options) + await setupRuby({}) } catch (error) { core.setFailed(error.message) } } +// entry point when this action is run from other actions async function setupRuby(options) { - const inputs = { ...inputDefaults, ...options } + const inputs = { ...options } + for (const key in inputDefaults) { + if (!inputs.hasOwnProperty(key)) { + inputs[key] = core.getInput(key) || inputDefaults[key] + } + } process.chdir(inputs['working-directory']) diff --git a/index.js b/index.js index d5647da..11c1c34 100644 --- a/index.js +++ b/index.js @@ -13,20 +13,23 @@ const inputDefaults = { 'working-directory': '.', } +// entry point when this action is run on its own export async function run() { try { - const options = {} - for (const key in inputDefaults) { - options[key] = core.getInput(key) - } - await setupRuby(options) + await setupRuby({}) } catch (error) { core.setFailed(error.message) } } +// entry point when this action is run from other actions export async function setupRuby(options) { - const inputs = { ...inputDefaults, ...options } + const inputs = { ...options } + for (const key in inputDefaults) { + if (!inputs.hasOwnProperty(key)) { + inputs[key] = core.getInput(key) || inputDefaults[key] + } + } process.chdir(inputs['working-directory'])