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

supports multiline output #937

Merged
merged 1 commit into from
Sep 12, 2021
Merged

supports multiline output #937

merged 1 commit into from
Sep 12, 2021

Conversation

pjxiao
Copy link

@pjxiao pjxiao commented Sep 12, 2021

Thank you so much for your work maintaining yq

Comment on lines +5 to +7
RESULT="${RESULT//'%'/'%25'}"
RESULT="${RESULT//$'\n'/'%0A'}"
RESULT="${RESULT//$'\r'/'%0D'}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This escape logic comes from a Github support case

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bash black magic 👍🏼

@pjxiao pjxiao marked this pull request as ready for review September 12, 2021 01:51
@mikefarah
Copy link
Owner

Cool thanks for the PR - happy to merge this in, do you mind explaining how this works first though?

@mikefarah mikefarah merged commit 25ba763 into mikefarah:master Sep 12, 2021
@pjxiao
Copy link
Author

pjxiao commented Sep 12, 2021

@mikefarah I appreciate your reply.

Suppose we have the following workflow:

jobs:
  convert-to-json:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: This outputs multiline JSON
        uses: mikefarah/yq@v4.12.2
        id: yaml-to-json
        with:
          cmd: yq eval --output-format=json 'config.yml'

      - run: echo "${{ steps.yaml-to-json.outputs.result }}"  # Currently we get only the first line

In the example above, we try to convert a YAML to a mutiline JSON but outputs.result contains only the first line.
example: https://github.com/pjxiao/yq-action/runs/3577428434 (please see 'Only the first line is saved' step)

My patch allows us to get an entire output even if the output contains line-breaks.
example: https://github.com/pjxiao/yq-action/runs/3577428423 (please see 'The entire JSON is saved' step)

The escaping logic:
The added escaping logic just URL encodes %, CR and LF. This originates in a community post. Though I researched documentations and references 1, I couldn't find any mentions of ecaping. So this behaviour is an internal specification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiline outputs support in the GitHub action
2 participants