Skip to content
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

Body fails when it contains double quotes. #13

Closed
bjeanes opened this issue May 18, 2020 · 8 comments
Closed

Body fails when it contains double quotes. #13

bjeanes opened this issue May 18, 2020 · 8 comments

Comments

@bjeanes
Copy link

bjeanes commented May 18, 2020

Like #10 (comment), probably need to replace " with \". The sed filter could probably be moved inline to toJsonOrNull to make sure it covers other fields (really just release name).

I know this action is semi-deprecated but I am also stuck on this until the GitHub provided one handles some of the same use cases as your fantastic action.

I'll try to open a PR to fix this but I've worked around it on my end already so unless it comes up again, I may forget, so I thought I'd document it in an issue for the time being.

bjeanes added a commit to bjeanes/indexer-sync that referenced this issue Jun 17, 2020
@meeDamian
Copy link
Owner

Hey, it should be fixed by 5264f5b, and I'll tag it as v2.0.2 soon.

@stm2
Copy link

stm2 commented Jul 2, 2020

Hey, now it fails when the body contains a backslash.
What worked for me
json_escape () {
printf '%s' "$1" | python -c 'import json,sys; print(json.dumps(sys.stdin.read()))[1:-1]'
}

The python dependency is the downside.
https://stackoverflow.com/questions/10053678/escaping-characters-in-bash-for-json

Actually, could you use jq itself?
echo $body | jq -R

@meeDamian
Copy link
Owner

@stm2 Can you check if #15 works for you with sth like:

uses: meeDamian/github-release@escaping
with:
	…

?

@meeDamian meeDamian reopened this Jul 2, 2020
@meeDamian
Copy link
Owner

Running a quick test in my test repo produced this release, looks good to me.

@stm2
Copy link

stm2 commented Jul 3, 2020

Uhm, I think it works as intended, but not for me. It has been a while or I'm beeing stupid. I'd like to do something like

jobs:
  build:
    steps:
      - name: Produce body
        run: |
          text=$(echo -e "Hello!\nWorld!\n")
          echo "set-env name=BODY::$text"
      - name: Create release
        uses: meeDamian/github-release@escaping
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          tag: ${{ env.TAG }}
          name: Pre-Release
          body: |
            ${{ env.BODY }}

But BODY only contains the first line. How would I go about producing a multiline body like this?

@meeDamian
Copy link
Owner

Could you try with:

body: >
  ${{ env.BODY }}

and

body: ${{ env.BODY }}

Also, I'd avoid using echo -e, or assigning from it w/o quotes (like text="$(…)").

text=$(echo -e "Hello!\nWorld!\n") 🤔

MacOS

MacOS 2020-07-03 at 20 07 22

Debian

MacOS 2020-07-03 at 20 17 40
Maybe try:
echo "set-env name=BODY::$(printf 'Hello!\nWorld!\n')"

or

text="Hello!
World!"

echo "set-env name=BODY::$text"

@stm2
Copy link

stm2 commented Jul 4, 2020

You were right about double quotes, of course. I figured out a workaround now from actions/create-release#11. The trick is

  text=$(cat CHANGELOG.txt; echo -e '\n\nHello, World!\n')
  text="${text//'%'/'%25'}"
  text="${text//$'\n'/'%0A'}"
  text="${text//$'\r'/'%0D'}"
  echo "set-env name=BODY::$text" 

They've also added a way to directly take the body from a file, which I find quite handy: actions/create-release#50

@meeDamian
Copy link
Owner

Ok, closing the issue again, as the problem seems to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants