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

Document how to use array outputs in job conditionals #509

Closed
pauleustice opened this issue Jan 16, 2025 · 2 comments
Closed

Document how to use array outputs in job conditionals #509

pauleustice opened this issue Jan 16, 2025 · 2 comments
Labels
question A question on how to use this action

Comments

@pauleustice
Copy link

pauleustice commented Jan 16, 2025

Is your feature request related to a problem? Please describe.

I find that the GitHub documentation around fromJSON/toJSON is not very clear, and it's not always obvious how to use data from github-script steps. I am especially stuck on how to use array outputs to conditionally run steps, which has led to lots of frustration. There is currently no documentation about how to do this, although I'd be happy to contribute some if I knew the answer!

For example (non-working):

- name: Some step
  if: ${{ steps.setArrayOutputs.outputs.jsArray.length > 0 }}

I have tried everything I can think of to get this to work, please see this workflow containing multiple tests (and associated workflow run).

Describe the solution you'd like

Better documentation on how to use data output from the github-script action.

@pauleustice
Copy link
Author

I think I now understand that you can't access length of arrays in the GH context, so please ignore

@joshmgross
Copy link
Member

@pauleustice if you still needed to do this, you could potentially use something like:

- name: Some step
  if: ${{ steps.setArrayOutputs.outputs.jsArray }}

or

- name: Some step
  if: ${{ toJSON(steps.setArrayOutputs.outputs.jsArray) != "[]" }}

I think either of those should work, but I haven't validated them.

@joshmgross joshmgross added the question A question on how to use this action label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question on how to use this action
Projects
None yet
Development

No branches or pull requests

2 participants