在 Github Actions 中获取 Shell 的标准输出并将其发布在 Pull Request 评论中。

huangapple go评论56阅读模式
英文:

In Github actions get Shell stdout and post it in a PR Comment

问题

我正在创建一个CI/CD流水线,尝试获取Shell脚本的输出并将其发布在PR评论中,以下是我目前的进展:

  • 名称:运行sh命令
    id:sh
    运行:bash ./update/commands.sh | tee output.txt

  • 名称:获取覆盖率输出
    id:get_coverage
    运行:echo "::set-output name=coverage < output.txt)"

  • 使用:mshick/add-pr-comment@v1
    参数:

    • 消息:
      覆盖率发现 ${{steps.get_coverage.outputs.coverage}}
      🌏
      !
    • 仓库令牌:${{ secrets.GITHUB_TOKEN }}
    • 仓库令牌用户登录:'github-actions[bot]' # 临时GitHub令牌的用户登录
    • 允许重复:false # 默认值
英文:

Im making a CI/CD pipeline and I'm trying to get the shell script output and post it in a PR comment and below is what I have so far.

I can see the shell script output when the pipeline runs but I struggling to save the output and post it in a PR comment.

      - name: run sh command
        id: sh
        run: bash ./update/commands.sh | tee output.txt
      - name: Get coverage output
        id: get_coverage
        run: echo &quot;::set-output name=coverage &lt; output.txt)&quot;
      - uses: mshick/add-pr-comment@v1
        with:
          message: |
            Coverage found ${{steps.get_coverage.outputs.coverage}}
            &#127759;
            !
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          repo-token-user-login: &#39;github-actions[bot]&#39; # The user.login for temporary GitHub tokens
          allow-repeats: false # This is the default

答案1

得分: 1

我个人会依赖 GitHub 命令行工具,非常容易向 Pull Request 添加评论:

gh pr comment 1234 --body-file file.txt

在这种情况下,我会将覆盖率的输出重定向到一个文件,然后将该文件的路径传递给 gh pr comment

确保你在工作流程文件中声明:

permissions:
  issues: write

以确保工作流能够向问题添加评论。

英文:

I'd personally rely on the github cli from which it's very easy to add a comment to a PR:

gh pr comment 1234 --body-file file.txt

In this case I would redirect the output of the coverage to a file and then pass the path to that file to gh pr comment.

make sure you declare:

permissions:
  issues: write

In the workflow file to ensure the workflow can add comments to the issue.

huangapple
  • 本文由 发表于 2023年3月3日 19:40:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75626631.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定