-
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
feat(core): add getBooleanInput function #725
Conversation
@ericsciple After I read the discussion in #362, I find that the YAML 1.2 core schema is implemented (#362 (comment)). So could we add the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution @yi-Xu-0100! I left some minor feedback before merging, happy to take the pr over if you don't have the time to continue working on this!
packages/core/src/core.ts
Outdated
* @param name name of the input to get | ||
* @returns boolean | ||
*/ | ||
export function getBooleanInput(name: string): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function getBooleanInput(name: string): boolean { | |
export function getBooleanInput(name: string, options?: InputOptions: boolean) { |
Lets keep consistent with the getInput
function. We really shouldn't throw if the value does not exist or is invalid, just return false. We can debug if the parsing does not match either case, to help with troubleshooting if users encounter this issue
We can add another option to InputOptions
to set a default value, and return that instead of false if needed as well. I'm happy to tackle that in another pr if you want.
@thboop Sorry for the delayed reply, I tried to fix the conflict with the main branch, but it didn't seem to get it right. 😅 So I pulled it again, attached my changes, and pushed it forcibly. The change of what I did:
For the error, I think the function is used to deal with boolean input, It should have a default value in |
Agreed, thanks for the contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for the contribution @yi-Xu-0100!
const val = getInput(name, options) | ||
if (trueValue.includes(val)) return true | ||
if (falseValue.includes(val)) return false | ||
throw new TypeError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if it was required: false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chamini2 The required: false
will be dealt with the getInput
(Line 107) and get the default value. 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if there is no default value, that will make val
an empty string, which we don't consider in line 108 or 109. Resulting in throw new TypeError
because trueValue.includes('')
and falseValue.includes('')
are both false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Action inputs can be read with
getInput
which returns astring
orgetBooleanInput
which parses a boolean based on the yaml 1.2 specification. If required set to be false, the input should have a default value inaction.yml
.
https://github.com/yi-Xu-0100/toolkit/blob/main/packages/core/README.md
@chamini2 Why a boolean type input have no default value? 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I did not know this was expected. If required: false
and no default I thought it had just to return null
or ''
. Thanks, sorry for the inconvenience.
Gets the input value of the boolean type in the YAML specification.
The return value is also in boolean type.
ref: https://yaml.org/type/bool.html
close #723