Skip to content

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

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

Open
quike opened this issue Apr 27, 2025 · 0 comments
Open

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

quike opened this issue Apr 27, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@quike
Copy link

quike commented Apr 27, 2025

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.

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

1 participant