1
0
Fork 0

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
pull/1659/head
John Andersen 2024-02-11 16:33:42 -08:00 committed by GitHub
parent a1b068ec31
commit 6cbb8ee6de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 2 deletions

View File

@ -87,8 +87,15 @@ export function addPath(inputPath: string): void {
* @returns string * @returns string
*/ */
export function getInput(name: string, options?: InputOptions): string { export function getInput(name: string, options?: InputOptions): string {
const val: string = let val: string = ''
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''
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) { if (options && options.required && !val) {
throw new Error(`Input required and not supplied: ${name}`) throw new Error(`Input required and not supplied: ${name}`)
} }