invalid dash/hyphen env variables in process action/core getInput
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.
I was unable to use https://github.com/github/local-action with inputs like one-potato because of this. I had to rename all of my inputs to use underscores instead of hyphens, like one_potato. It would be great to fix the replace expression:
const val: string =
process.env[`INPUT_${name.replace(/[ -]/g, '_').toUpperCase()}`] || ''