如何让GitHub Actions中github-script的输出换行显示?
解决GitHub Actions PR评论换行问题
你的代码存在两处关键问题导致换行不生效,按以下方案修改即可:
修正模板字符串引号不匹配问题
你代码里的const output =line one \n line two'`结尾用了单引号,需和开头的反引号保持一致,改为:const output = `line one \n line two`适配GitHub Markdown换行规则
GitHub评论采用Markdown语法,单纯的\n仅在代码层面换行,显示时不会生效,可通过两种方式解决:- 方式一:用
\n\n实现段落分隔(Markdown中空一行才会显示换行):const output = `line one \n\n line two` - 方式二:使用HTML
<br>标签强制换行:const output = `line one <br> line two`
- 方式一:用
修改后的完整流水线示例:
jobs: my-job: runs-on: ubuntu-latest steps: - uses: actions/github-script@v6 with: script: | const output = `line one \n\n line two` github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: output })
内容的提问来源于stack exchange,提问作者Nespony
相关产品推荐
相关产品推荐

