Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/__tests__/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,12 @@ describe('@actions/core', () => {

it('getInput gets non-required input', () => {
expect(core.getInput('my input')).toBe('val')
expect(core.getInput('my-input')).toBe('val')
})

it('getInput gets required input', () => {
expect(core.getInput('my input', {required: true})).toBe('val')
expect(core.getInput('my-input', {required: true})).toBe('val')
})

it('getInput throws on missing required input', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function addPath(inputPath: string): void {
*/
export function getInput(name: string, options?: InputOptions): string {
const val: string =
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''
process.env[`INPUT_${name.replace(/[- ]/g, '_').toUpperCase()}`] || ''
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would break many test setups that define, say, process.env.["INPUT_WHO-TO-GREET"]. You need some code to maintain backwards-compatibility, i.e.

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

Having said that, I have yet to see any actions/ PR getting accepted when the PR author doesn't happen to work at GitHub. I don't understand the policy (at least I assume that there is an internal, not publicly communicated, policy not to accept "outside PRs"...) but that's what I have observed in the past. Not trying to spoil the party here, but wanting to dampen both your and my hopes to reflect realistic expectations.

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