Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getInput empty returned value #1624

Open
y-nk opened this issue Jan 11, 2024 · 1 comment
Open

getInput empty returned value #1624

y-nk opened this issue Jan 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@y-nk
Copy link

y-nk commented Jan 11, 2024

Describe the bug

When using core.getInput in a composite action, the returned value is empty.

To Reproduce
Steps to reproduce the behavior:

  1. Create a composite action with an input
  2. Use github-script action and try core.getInput on the input
  3. Use the composite action in a workflow
  4. Set the input with a value
  5. See error

Expected behavior

The value should be returned as provided

Additional context

The root cause is known and is on actions/runner side (here) but i think we should so something about it in here too. A warning about missing env var could be a quick win, and avoid people not knowing why it failed.

Proposed implementation

/**
* Gets the value of an input.
* Unless trimWhitespace is set to false in InputOptions, the value is also trimmed.
* Returns an empty string if the value is not defined.
*
* @param name name of the input to get
* @param options optional. See InputOptions.
* @returns string
*/
export function getInput(name: string, options?: InputOptions): string {
const val: string =
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''
if (options && options.required && !val) {
throw new Error(`Input required and not supplied: ${name}`)
}
if (options && options.trimWhitespace === false) {
return val
}
return val.trim()
}

export function getInput(name: string, options?: InputOptions): string {
  const inputKey = `INPUT_${name.replace(/ /g, '_').toUpperCase()`
    
  const val: string =
    process.env[inputKey] || ''

  if (!(inputKey in process.env)) {
    warn(`the input '${inputKey}' is missing from env`)
  }

  if (options && options.required && !val) {
    throw new Error(`Input required and not supplied: ${name}`)
  }

  if (options && options.trimWhitespace === false) {
    return val
  }

  return val.trim()
}
@vincerubinetti
Copy link

If you're trying to get an input while using actions/github-script, as I am, you can work around this by just using normal expression substitutions (orwhatever they're called):

// const workingDirectory = core.getInput("working-directory");
const workingDirectory = "${{ inputs.working-directory }}";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants