mirror of https://github.com/actions/toolkit
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/629pull/1659/head
parent
a1b068ec31
commit
6cbb8ee6de
|
@ -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}`)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue