pull-request icon indicating copy to clipboard operation
pull-request copied to clipboard

multiline Body not working

Open krtschmr opened this issue 3 years ago • 3 comments

we would like to reference by commit message convention to have related tickets autoclosed

      - name: get the PR body
        run: |
          echo "👑 *An automated PR* 👑\n\n" > pr_msg
          git log origin/master..origin/staging --no-merges --pretty='format:%s' > diff
          cat diff | grep -oP '\[#[0-9]{4,5}\]' | grep -v "0000" | grep -oP '\#[0-9]{4,5}' >> pr_msg
          sed -i 's/#/closes #/g' pr_msg

⬆️ this works great and produces a file like

closes #1234
closes #9854
closes #1235

We continue to grab it via actions and then reuse it in the PR Body

      - name: Get message
        id: vars
        run: echo ::set-output name=pr_body::$(cat pr_msg)

     ...
          source_branch: ${{ steps.branch.outputs.name }}
          destination_branch: "master"
          pr_title: "🚢 ${{ steps.branch.outputs.name }} - SHIP IT :shipit:"
          pr_body: ${{ steps.vars.outputs.pr_body }}
image

What would be the correct way of having the new lines respected?

krtschmr avatar Sep 29 '22 06:09 krtschmr

There is currently an open PR for this https://github.com/repo-sync/pull-request/pull/89

wei avatar Sep 30 '22 05:09 wei

thanks @wei

krtschmr avatar Sep 30 '22 06:09 krtschmr

it didn't fixed it.

@wei I forked, merged the PR #89 into our master and used it. the result is this:

image

branch i used: https://github.com/dcflw/pull-request/commits/master

krtschmr avatar Sep 30 '22 06:09 krtschmr

It seems to be working in https://github.com/Telefonica/mistica-icons/blob/8ece560530b0277eb0bd41aaddfc507d9ddf3dae/.github/workflows/figma-export.yml#L284-L286

Example PR: https://github.com/Telefonica/mistica-icons/pull/233

Can you wrap it with quotes similar to the one in the comment?

wei avatar Nov 01 '22 14:11 wei

i will give it a try tomorrow!

krtschmr avatar Nov 01 '22 14:11 krtschmr

i'll try this now . will feedback.

image

krtschmr avatar Nov 02 '22 08:11 krtschmr

still not working. more details here: https://github.com/repo-sync/pull-request/pull/89#issuecomment-1301282166

krtschmr avatar Nov 02 '22 21:11 krtschmr

@krtschmr Here is a another simple working example:

Code: https://github.com/wei/test-pr/blob/15f57cc1439fde8185f60a4cd3455c6a0c1a7e1b/.github/workflows/pr.yml#L17-L20 Pull Request: https://github.com/wei/test-pr/pull/11

I don't know how your string is constructed I recommend reading more about how yml treats your string. https://yaml-multiline.info/

wei avatar Nov 02 '22 23:11 wei

Alternatively:

image image

wei avatar Nov 02 '22 23:11 wei

thanks. i didn't know about yaml multiline foo. will try now

          pr_body: |
            ${{ steps.vars.outputs.pr_body }}

krtschmr avatar Nov 03 '22 07:11 krtschmr

this also doesn't work for us. the string itself contains multiple \n but the outcome is still. no matter what syntax on yaml i use.

image

krtschmr avatar Nov 03 '22 07:11 krtschmr

As per my screenshot in the last comment, the string needs to contain actual line breaks instead of the text "\n". Can you verify that is the case in the output variable you created?

wei avatar Nov 03 '22 09:11 wei

then i understand. so we cannot pass strings, containing \n. then this issue is settled. or actually another issue, maybe worth adressing?

krtschmr avatar Nov 03 '22 09:11 krtschmr

I don't believe this is another issue as it's working as expected from my testing above.

You just need to pass pr body string containing actual line breaks as seen in the examples I provided.

wei avatar Nov 03 '22 10:11 wei

i mean, yes, those are line breaks.

image

krtschmr avatar Nov 03 '22 10:11 krtschmr

it's also not really important to us actually. ruby puts(array) does also add new lines and then we have the closes XZY just in one line rather than multilines. it still works and creating the PR is awesome 🥳

krtschmr avatar Nov 03 '22 10:11 krtschmr

Thanks for bareing with me. Found the root cause as GitHub actions is truncating multiline outputs.

ref: https://github.com/community/community/discussions/26288

Also, the way you set output variable is being deprecated. It will likely be fixed once you update how you set your output.

ref: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

wei avatar Nov 03 '22 10:11 wei

allright. i saw the deprecation but never looked into it yet. writing key=valyue into one object sounds way easier. i'll give it a shot in the near future and report back to you. thanks for your effort!

krtschmr avatar Nov 03 '22 10:11 krtschmr