Skip to content
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

fix: Do not merge missing default value into Action inputs #1176

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shrink
Copy link

@shrink shrink commented Jun 28, 2021

Closes #924

At present, an Input without a default value is given a default value of an empty string, meaning there's no way for Action authors to differentiate between "no value was provided" and "an empty string was provided". As described in #924, this introduces a number of challenges for Action authors and has been acknowledged as a (low priority) bug.

The change in this Pull Request is very simple: do not set a default string value when no default is provided -- using a NullToken instead of a StringToken. As a consequence, the INPUT_* environment variables will now only contain a value when an input or default is provided.

Backwards Compatibility

The GitHub Actions toolkit package core provides a getInput method which checks for the presence of the environment variable and uses a default empty string if the environment variable is not found, therefore this change would not break the behaviour of the toolkit. However, it would enable the introduction of hasInput as described in my Pull Request feat: Check if action run hasInput #849.

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

https://github.com/actions/toolkit/blob/45647689407e7fb224e06d066dde6aefa67a365f/packages/core/src/core.ts#L80-L101

I've performed various tests of this against my own actions (like actions-assert) and experienced no issues, so I'm fairly confident in saying it works without issue.

Previously

action.yml

inputs:
  example:
    description: "Example of an optional input with no default"
- uses: ./
- run: printenv INPUT_EXAMPLE
$ printenv INPUT_EXAMPLE
''

With this change

action.yml

inputs:
  example:
    description: "Example of an optional input with no default"
- uses: ./
- run: printenv INPUT_EXAMPLE
$ printenv INPUT_EXAMPLE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Differentiate between input parameter empty or not present
1 participant