-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
set-env truncates multiline strings #403
Comments
#405 also possibly related although multiline input should already be string. |
Afaik there isn't a bug in the toolkit. When using the toolkit function, newlines are escaped. When echo'ing the command manually (the community issue) the user must escape. |
Thanks, makes sense. Since the recommendation was to post an issue here, I thought workflow and toolkit were linked, eg. that workflow is using the toolkit. Where would be the appropriate place then to provide documentation about manual escaping ? It seems to be a recurring issue. |
@thboop it sounds like the command docs are missing info about escaping:
@andreasplesch in the community issue it looked like the user was echoing the command manually. It was a The function in the toolkit (npm module) does the escaping and then prints the formatted command |
https://help.github.com/en/actions/reference/workflow-commands-for-github-actions would be perfect for escaping info. I also noticed that problem matcher doc is missing there. |
from a end-user perspectiv, its highly supprising that a line like when setting the outout var based from a cli command like would be great this could work out of the box |
The real solution presumably would be to not have to escape at all. Why should % and newlines be special ? |
What? This seems nuts to expect a user to do the escaping manually. |
Piling on here - I found this very surprising as well, as a user. |
It gets more tricky if your other steps are using containers (though for speed I would recommend trying to avoid using containers where at all possible) but writing your output to a file (e.g. in /tmp) is another workaround. 🤷♂️ |
Unfortunately The runner is reading stdout from the child process. The runner has to assume the value ends when it reaches the end of the line. Other options would be something like, if the runner added a tool in the PATH to call instead which deals with escaping. For example, Or a different approach would be if the runner supported a heredoc style when writing stdout commands. For example:
|
but rather %0A as suggested in actions/toolkit#403
Hello, I'm a little bit lost with what is actually happening here. I'm trying to use the bash replacement but it seems like the output coming from a yarn script is already truncated to a the first line. I have this code https://github.com/wachunei/directUC/actions/runs/200970194/workflow#L30 Do any of you know if there is a workaround to this that might work in my context? Thank you. |
If the first echo output after running the yarn script is unexpected, seeminlgy truncated to one line, it is perhaps an issue with the yarn script rather than with actions. Do the two lines work from an interactive bash shell ? |
I thought the same, so this morning I turned this into a bash script wrapping the yarn output and the issue is still happening. In this echo output I'm getting the first line only https://github.com/wachunei/directUC/actions/runs/201452370/workflow#L32 But if I run this locally it seems like it is a single line output, this is also more confusing, are these chars ignored in the echo? I'm mostly a front end developer, this is my first time trying to make automatic things like a release on tag push and add a body coming from a script to it, I really appreciate you taking your time to comment! |
I am noticing you are using zsh, not bash, interactively, and the the bash script is missing the the double quotes. You will need to be careful with the exact settings. Is the interactive yarn output as expected ? |
With bash is the same output, without or with doublequotes (I added them though!). It is not as expected since I'm not passing the Update: this is the updated script with correct output locally #!/usr/bin/env bash
OUTPUT="$(yarn run --silent auto-changelog --stdout -t ./.changelog/release-template.hbs $@)"
echo $OUTPUT |
generates multi-line output ? You probably need double quotes around $OUTPUT to avoid word splitting. |
I added those, it generates multiline locally 👍🏼. In the runner I'm still getting the first line only https://github.com/wachunei/directUC/runs/964094234?check_suite_focus=true#step:7:11 |
ok. Just try directly in the yaml wthout the release.sh:
I do not know yarn enough but it seems strange to invoke yarn with another yarn call. |
Although, it seems ok to do that. But the outer yarn is missnig the stdout option. |
I do it because from the yaml I just run a yarn script, and the yarn script runs auto changelog (or the .sh that makes yarn run the auto changelog since this morning) the I'm getting the exact same result :( |
hm, right. Perhaps yarn is outputting to stderr ?
|
stdout is correctly redirected to output with expected multiple lines |
ok. Perhaps try that in the yaml ? [ The question was if stdout is used in the first place but it seems to be. ] |
Same output, I thought setup-node might be installing yarn v2 but it is the same yarn version that I'm using locally https://github.com/wachunei/directUC/runs/964164661?check_suite_focus=true#step:9:4 |
Add me to the list of people who had to spend hours to figure out that multiple lines were being truncated. It was especially confusing for me because the first line of my output was blank so I was just getting nothing. Additionally, using the escaping as suggested, my output is full of single-quotes for some reason. Here's the first step (Bash):
Second step, using
The result I get in Slack is like this:
I cannot figure out where those single-quotes are coming from. They are not in the output file when assigned. Also, each line has multiple space characters for indentation, which is why we surround the output in ````` sets to achieve pre-formatted text. But the multiple spaces are reduced to one single space (an HTML like conversion??). |
I figured out a work-around for my use-case. I realized since I'm sending this to Slack via the 'args' argument, I needed newlines to be a literal '' and 'n' in what was output to that command. And then I "fixed" the spaces by replacing space characters with a Unicode 'En Space' character:
Which is resulting in the correct output:
|
For |
i had the same issue as @happiness801 described here
the only solution that i found that works is to remove the single quotes from the accepted answer:
|
@thboop thanks - could we add a short note about set-env being deprecated to those docs? Otherwise people who see mentions of it via web search, or existing workflows, etc are going to be confused that there's no mention in that doc (and that GITHUB_ENV is the replacement). Thanks!! |
GitHub workflows' `set-output` command uses the OS's EOL character for ending the capture, which means `\n` characters must be replaced with something else. The community wisdom is `%0A`; see actions/toolkit#403. The `${{ github.repository }}` expression's `/` delimiter conflicts with the `sed` delimiter; avoid this by changing the `sed` delimiter to `#`.
GitHub workflows' `set-output` command uses the OS's EOL character for ending the capture, which means `\n` characters must be replaced with something else. The community wisdom is `%0A`; see actions/toolkit#403. The `${{ github.repository }}` expression's `/` delimiter conflicts with the `sed` delimiter; avoid this by changing the `sed` delimiter to `#`.
|
what should be used instead? |
The If you are using the toolkit core command You can see a security advisory that prompted this here |
This came up in the forum: https://github.saobby.my.eu.orgmunity/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/m-p/52511/highlight/true#M8539
with a suggestion to post an issue here.
the enhancement
Please add an example to the docs, probably in https://github.com/actions/toolkit/blob/master/docs/commands.md, on how to best allow for multi-line value in set-env or set-output.
Code Snippet
The suggested solution in the forum is to manually escape newlines in the shell script with
potential bug
https://github.com/actions/toolkit/blob/master/packages/core/src/command.ts#L76
already should escape, so perhaps something else is not working.
#193 seems related.
The text was updated successfully, but these errors were encountered: