actions / actions/toolkit

Impossible to detect unset inputs from inputs set as the empty string

Open
#940 0 comments 23 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.9k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
As a GitHub Actions author, it is impossible to tell the difference between an unsupplied input and an input set to the empty string.

There is no way for me, as an Actions author, to tell the difference between these two user-supplied workflows:

steps:
- uses: 'foo/bar'
  with: 
    my_value: ''

and

steps:
- uses: 'foo/bar'

In both instances, core.getInput('my_value') will result in the empty string, even though the second instance is explicitly null. Even explicitly setting the value to null results in the value being set to the empty string:

steps:
- uses: 'foo/bar'
  with: 
    my_value: ~

This is problematic when mixed with GitHub secrets, because when secrets are not available (such as from a fork), they are injected as they wind up appearing as the empty string. This makes it impossible to distinguish between an unsupplied input and an input set to the empty string.

The primary use case is around providing a more informative error to the end user. In the case where the input is completely missing, this is a "syntax error" (the user needs to fix their workflow file). However, in situations where the input exists but has a value of the empty string, we can hint toward other possibilities (such as secrets injection or missing envvars), because it's highly unlikely someone would actually use the empty string as a value (it's most likely coming from some interpolation that's secretly failing).

I know inputs are actually transformed envvars, so I explored trying to read process.env directly in https://github.com/google-github-actions/auth/pull/54. Normally something like the following would work:

const hasValue = `INPUT_MY_VALUE` in process.env;

However, it appears that GitHub Actions initializes all inputs to the empty string, even when they are explicitly not given. Furthermore, even when I set a default value of ~ (null) in the Actions metadata file, the environment variable value is still set to the empty string. This makes it impossible to distinguish between "no value given" and "value is the empty string".

Expected behavior
There should be a way to determine if a value was given.

Screenshots

  • N/A

Desktop (please complete the following information):

  • N/A

Smartphone (please complete the following information):

  • N/A

Additional context
Add any other context about the problem here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with core.getInput and the process.env behavior described in the issue, comparing omitted inputs with explicitly empty values and null defaults. Done means an Actions author can reliably determine whether an input was supplied, with the behavior verified for the workflow examples given.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, typescript
Domain
ci-cd, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.