Skip to content

invalid dash/hyphen env variables in process action/core getInput #2034

Open
@quike

Description

@quike

Describe the bug

Core here: https://github.com/actions/toolkit/blob/main/packages/core/src/core.ts#L153

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

Current @action/core getInput replaces the name string to find it as env variable in the process. It changes any whitespace with underscore. So if the name is potato it tries to find INPUT_POTATO. If the name is one potato it tries to find INPUT_ONE_POTATO. But it does only replace white spaces. Any given dash/hyphen example keeps it with the dash/hyphen, what is an invalid case on bash or POSIX shells.

Actions allow arguments with dash/hyphen like the example here:

# Define your inputs here.
inputs:
  who-to-greet:
    description: Who to greet
    required: true
    default: World

So I assume there is an existing preprocessing for GitHub actions where any dash/hyphen separated key gets transformed to underscore, as GitHub uses Octokit and it doesn't accept dash/hyphen in variables keys either.

This is a problem outside of GitHub ecosystem or without using the action.yml as if you want to reuse the library (for example in GitLab) the use of dash/hyphen is not accepted.

To Reproduce
Try to use @action/core getInput call with an dash/hyphen case.

Expected behavior

Replacing the regex with:

  const val: string =
    process.env[`INPUT_${name.replace(/[- ]/g, '_').toUpperCase()}`] || ''

should swap any white space and any dash/hyphen with an underscore, creating a valid environment variable key. That should allow anyone using the action outside from a github action to consume it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions