Skip to content

Commit

Permalink
Update getInput to also support loading from underscored env vars
Browse files Browse the repository at this point in the history
Rather than just hyphens, eases calling from other contexts,
such as when testing.

Closes: actions#629
  • Loading branch information
pdxjohnny committed Feb 12, 2024
1 parent a1b068e commit 6cbb8ee
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/core/src/core.ts
Expand Up @@ -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}`)
}
Expand Down

0 comments on commit 6cbb8ee

Please sign in to comment.