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

core.setOutput should(?) transform data to a string #370

Closed
JasonEtco opened this issue Mar 4, 2020 · 7 comments
Closed

core.setOutput should(?) transform data to a string #370

JasonEtco opened this issue Mar 4, 2020 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@JasonEtco
Copy link
Collaborator

Describe the enhancement

Hello! In an action I maintain, I call setOutput with an issue number. That fails, because setOutput expects it to be a string. This bit me (JasonEtco/create-an-issue#46), and I'm wondering if y'all would be up for transforming the value passed to a string, or throwing if it isn't a string.

I realize that this gets into "just use TypeScript" territory, but I see no reason that I shouldn't be able to pass a number aside from the implementation detail of how it works under the hood.

Code Snippet

// Doesn't work but could
core.setOutput('issue_number', 1)

// Does work
core.setOutput('issue_number', '1')
core.setOutput('issue_number', String(1))

Additional information

I'm using JasonEtco/actions-toolkit as an opinionated alternative/wrapper for actions/toolkit. If transforming the value isn't something y'all feel good about, I'm happy to move that into that more opinionated territory!

@JasonEtco JasonEtco added the enhancement New feature or request label Mar 4, 2020
@ericsciple
Copy link
Contributor

ericsciple commented Mar 5, 2020

@thboop thoughts?

I think this makes sense. Especially given common cases like bool/number.

The only thing that worries me a little bit, is if we ever preserve type/structure in the future. Basically to enable something like ${{ steps.foo.outputs.bar.subproperty }}. However we could always overload in the future... Also it's nice to just keep it simple (outputs are strings), so i think converting to string makes sense.

I wonder for arrays/objects, whether we should convert to json (indented?) or just defer to however nodejs converts to string - for example:

`${[1, 2, 3]}` // '1,2,3'

i kind of like just doing whatever nodejs does (no magic)

@JasonEtco
Copy link
Collaborator Author

Thanks for sharing those thoughts @ericsciple, there are a couple of complications you mentioned.

I wonder for arrays/objects, whether we should convert to json (indented?)

This is an interesting choice; using the String primitive on an object, it does this:

String({ test: true })
// -> "[object Object]"

Which is not at all useful. This is way better:

JSON.stringify({ test: true })
// -> '{ "test": true }'

JSON.stringify can also be applied numbers, arrays an booleans - so that might be a nice catch-all approach.

@thboop thboop self-assigned this Mar 6, 2020
@thboop
Copy link
Collaborator

thboop commented Mar 6, 2020

I think stringifying makes a lot of sense. Bools and numbers are probably the most common case here, but we should consider others (like json).

Also it's nice to just keep it simple (outputs are strings), so i think converting to string makes sense. Agreed.

@JasonEtco
Copy link
Collaborator Author

JasonEtco commented Mar 6, 2020

One thing to note is that there may be an expectation that whatever you setOutput will be the same type on the other end - that sounds like something for docs (and obviously TypeScript).

@ericsciple
Copy link
Contributor

+1 i would just write in the function description that it runs JSON.stringify for any values that arent a string

some quirks to be aware of :)

JSON.stringify(null) // 'null'
JSON.stringify(undefined) // undefined - so need to explicitly handle undefined

@jetersen
Copy link

jetersen commented Mar 15, 2020

Fell into this trap: release-drafter/release-drafter#376 (comment)

@thboop
Copy link
Collaborator

thboop commented Apr 13, 2020

Resolved in #405

@thboop thboop closed this as completed Apr 13, 2020
kittaakos pushed a commit to kittaakos/upload-s3-action that referenced this issue Aug 4, 2020
 - Log the `message` of the  `Error` object. [actions/toolkit#370]
 - Streamlined output to string for `fromjson`.
 - Aligned the documenation with the new `object_locations`value.
 - Regenerated `dist`.

Closes shallwefootball#9

Signed-off-by: Akos Kitta <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants