[Bug] echo string with escaped newlines fails

When running echo ${{ toJson(github) }} as a step, it fails when pushing a commit with multi-line commit message.



This is what immediately precedes the line where timestamp is echoed

"message": "Merge pull request #9 from MrSkwiggs/master\n\nUpdate test.yml",
"timestamp": "2020-10-09T09:36:42+02:00",

To avoid issues with multiple lines or command substitution, the documentation suggests to use env:

steps:
  - name: Print github context
    env:
      GITHUB_CONTEXT: ${{ toJSON(github) }}
    run: echo "$GITHUB_CONTEXT"

An alternative in bash is to use cat with heredoc syntax and quotes around the delimiter definition to disable substitution:

steps:
  - name: Print github context
    run: |
      cat<<'EOF'
      ${{ toJSON(github) }}
      EOF
1 Like