-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Suggest adding core.setBooleanOutput
function - specifying a boolean for core.setOutput
does not work as expected
#1368
Comments
This is working as expected based on the documentation - I'm gonna doubt your report will be addressed (i'm not a maintainer btw)
|
@sounisi5011 you just need to |
It is true that this is the expected behavior based on the documentation. Therefore, I have not labeled this issue as a bug. What I am arguing is that the current specification, where the value passed to This library is written in JavaScript and is intended to be used with JavaScript. Users would expect it to handle booleans in the same way as JavaScript. However, the GitHub workflow interprets values differently than JavaScript. If users do not read the documentation carefully, they may end up implementing custom JavaScript actions in the wrong way. In my opinion, #370 is wrong in deciding to convert the value passed to the Alternatively, I suggest adding a note to the Few users would notice this problem with just the sentence "Non-string values will be converted to a string via JSON.stringify". |
core.setOutput
does not work as expectedcore.setBooleanOutput
function - specifying a boolean for core.setOutput
does not work as expected
Describe the enhancement
If a boolean is specified for
core.setOutput
, it will be converted to a JSON string and output.For example,
core.setOutput('result', false)
sets the string"false"
to output "result".However, the string
"false"
evaluates to true within the conditional expression.Because this is not an empty string, it is converted to
1
, and then1
is evaluated astrue
.see https://docs.github.com/en/actions/learn-github-actions/expressions#operators
I do not think this behavior is correct.
The user would think that using
core.setOutput('result', false)
would set "result" to a value that evaluates to false.Code Snippet
Currently, this code returns the string
"false"
.hus, the user must write the following to use the output "result" in a conditional expression:
It should return an empty string that evaluates to false or should not set output.
Then the user can use the output in a conditional expression in GitHub actions.
My suggestion
This is not a bug. This behavior follows the documentation. Changing the behavior of the
core.setOutput
function would be a breaking change that would break backward compatibility.However, few users would notice this problem with just the sentence "Non-string values will be converted to a string via JSON.stringify".
Therefore, I suggest adding a new
core.setBooleanOutput('result', false)
function.This function returns the string value
"true"
iftrue
is passed, or the empty string""
iffalse
is passed.It throws an error if a non-boolean value is passed. After adding this function, add a statement to the
core.setOutput
function documentation such as "If you want to specify a boolean, you may want to use the core.setBooleanOutput function instead".Alternatively, I suggest adding a note to the
core.setOutput
function documentation about the trap regarding how to interpret expressions in the GitHub workflow.see #1368 (comment)
The text was updated successfully, but these errors were encountered: