fix: Do not merge missing default value into Action inputs #1176
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 aStringToken
. As a consequence, theINPUT_*
environment variables will now only contain a value when an input or default is provided.Backwards Compatibility
The GitHub Actions toolkit package
core
provides agetInput
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 ofhasInput
as described in my Pull Request feat: Check if action run hasInput #849.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
With this change
action.yml
$ printenv INPUT_EXAMPLE