question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use ${{ toJson(github) }} when a ' appears in the commit message.

See original GitHub issue

Describe the bug When trying to use ${{ toJson(github) }} when there is a ’ in the commit message, you get an error. The error looks like, unexpected EOF while looking for matching `"’

To Reproduce Steps to reproduce the behavior:

  1. Have a workflow bash script that tries to run ${{ toJson(github) }} that runs on a PR
  2. Leave a commit message including a ’ character
  3. Trigger the workflow by opening a PR
  4. You should see the toJson step fail with the error message above.

Expected behavior Expected to see the full pretty printed github context

Runner Version and Platform

Current runner version: ‘2.287.1’

OS of the machine running the runner? OSX/Windows/Linux/… Ubuntu 20.04.3 LTS

What’s not working?

toJson expression

Job Log Output

unexpected EOF while looking for matching `"’

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

17reactions
nikola-jokiccommented, Feb 4, 2022

Hi @petersutter5,

I reproduced the issue. toJSON will create a JSON object, and since ’ is a valid thing to be inside the name (strings are enclosed using "), it will not be escaped. Now, if you are using an expression like echo '${{ toJSON(github) }}', it will trigger a parsing error when it gets to the ’ inside the "title".

One suggestion can be to pass in the context as env variable, and then printing or using it would not cause an issue:

jobs: 
  build:
    runs-on: [ ubuntu-latest ]
    steps:
      - name: Dump GitHub context
        id: github_context_step
        run: echo $JSON
        env:
          JSON: ${{ toJSON(github) }}

This is a bash error, and you can take advantage of bash’s built-in escaping of env variables to solve the problem like in the workflow above.

9reactions
atsu85commented, Sep 8, 2022

@nikola-jokic , thanks for the workaround, but note that official documentation also contains example that triggers this issue, without warning about escaping issues image It would be nice to add second warning there about this issue and potential workaround

Read more comments on GitHub >

github_iconTop Results From Across the Web

GitHub Action Get Commit Message
Or it is possible to get the commit messages with the git log command if you use bash: git log -1 --pretty=format:"%s".
Read more >
Source Control with Git in Visual Studio Code
You can find the details in Git commit information. Stage all changes button. You can type a commit message above the changes and...
Read more >
Returning Git Commit Information as JSON
No one cannot remember who updated the server X or when it was updated. ... Let's find out how we can configure the...
Read more >
Push rules | GitLab
This push rule requires a Signed-off-by: trailer in every commit message, ... Do not allow users to remove Git tags with git push...
Read more >
Comments on individual commits made outside a pull ...
A commit comment cannot be added from the pull request page and cannot be replied to or resolved like a pull request review...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found