invalid dash/hyphen env variables in process action/core getInput
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.9k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at packages/core/src/core.ts around getInput (line 153) and trace how an input name becomes an environment-variable key. Reproduce a hyphenated name such as who-to-greet, add coverage for the expected lookup behavior, and run the core package's relevant tests to verify it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- github-actions, typescript
- Domain
- ci-cd, developer-experience
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100