Process Escape Characters in Release `body`
My use case: I'm using an environment variable to pass a parsed sub-section of my changelog into the release body.
The environment variable is defined in a previous step using https://help.github.com/en/actions/automating-your-workflow-with-github-actions/development-tools-for-github-actions#set-an-environment-variable-set-env. From what I can tell, this logging command does not work with multi-line environment variables unless the newlines are escaped, so I replaced the newline character with the ascii characters \n. This environment variable can be passed successfully to further steps, and echo -e $CHANGELOG processes the escaped characters and shows newlines as expected.
But when passing body: ${{ env.CHANGELOG }} to actions/create-release, the created release shows ascii \n characters instead of newlines. Would it be possible to process escape characters in the body the same way echo -e does? If this isn't desired as default behaviour, could an input be added to specify this?
Thanks :)
I found out that you can set outputs with newlines, if you replace newlines with the literal characters %0A
e.g., echo "::set-output name=my_output::hello%0Aworld%0A!"
Presumably also works with ::set-env although I haven't tried
Here is the workaround I'm using now:
text="${text//'%'/'%25'}"
text="${text//$'\n'/'%0A'}"
text="${text//$'\r'/'%0D'}"
echo "::set-output name=value::$text"
And using master
- name: Create ${{ steps.tag.outputs.value }} release
id: create_release
uses: actions/create-release@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ steps.tag.outputs.value }}
body: |
${{ steps.release_notes.outputs.value }}
draft: true
prerelease: false
So my script generates a table of metrics for my bachelor thesis:
Relevant code
def print_result(analysis_result: Dict[str, Any]) -> None:
data = sorted([(k, v) for k, v in analysis_result.items()])
to_print = "### Metrics\n" + tabulate.tabulate(data, tablefmt="github")
# use newline char for url encoding instead of standard one
# to get multiline output shown in release body
to_print = to_print.replace('\n', '%0A')
print(to_print)
Output (standard output)
'### Metrics%0A|------------|-----|%0A| citations | 3 |%0A| figures | 0 |%0A| pages | 30 |%0A| tables | 0 |%0A| word_count | 510 |'
In the CI job console, the table is shown correctly:

However, in the release, the table becomes malformed like these:

Can someone help me out finding the problem here?
Nevermind, the problem is that multiple continous whitespace characters are replaced by one in HTML (and thus Markdown rendering). So I ended up adding fenced code blocks characters.
Thanks @walfie and @trung! I found that I had to tweak the search and replace a little, so I ended up with:
text="${text//$'%'/%25}"
text="${text//$'\n'/%0A}"
text="${text//$'\r'/%0D}"
echo "::set-env name=value::$text"
Also I can confirm it works with ::set-env as expected.