Skip to content
This repository was archived by the owner on Mar 4, 2021. It is now read-only.
This repository was archived by the owner on Mar 4, 2021. It is now read-only.

Process Escape Characters in Release body #25

Open

Description

@nathanielatom

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 :)

Activity

  1. walfie commented on Nov 27, 2019

    @walfie

    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

  2. trung commented on Dec 6, 2019

    @trung

    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
  3. added a commit that references this issue on Dec 27, 2019
  4. nazarimilad commented on Dec 27, 2019

    @nazarimilad

    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:

    image

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

    image

    Can someone help me out finding the problem here?

  5. nazarimilad commented on Dec 27, 2019

    @nazarimilad

    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.

  6. nathanielatom commented on Jan 17, 2020

    @nathanielatom
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions