From 6cbb8ee6deb610004ff5af28bad0e79b2a493bee Mon Sep 17 00:00:00 2001 From: John Andersen Date: Sun, 11 Feb 2024 16:33:42 -0800 Subject: [PATCH] Update getInput to also support loading from underscored env vars Rather than just hyphens, eases calling from other contexts, such as when testing. Closes: https://github.com/actions/toolkit/issues/629 --- packages/core/src/core.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index 2a8b8fd4..5a95e349 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -87,8 +87,15 @@ export function addPath(inputPath: string): void { * @returns string */ export function getInput(name: string, options?: InputOptions): string { - const val: string = - process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || '' + let val: string = '' + + for (let possibleEnvVarValue of [process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`], process.env[`INPUT_${name.replace(/-/g, '_').replace(/ /g, '_').toUpperCase()}`]]) { + if (possibleEnvVarValue) { + val = possibleEnvVarValue + break + } + } + if (options && options.required && !val) { throw new Error(`Input required and not supplied: ${name}`) }