gpt4 book ai didi

github-api - 如何将 Markdown 页面附加到 GitHub 操作工作流运行摘要?

转载 作者:行者123 更新时间:2023-12-04 03:26:33 25 4
gpt4 key购买 nike

The GitHub Action "dotnet-tests-report"将带有测试结果的 Markdown 页面附加到 Github Action 工作流运行摘要。这真的很好。工作流程完成后,结果是什么就变得很清楚了。以视觉方式清除。
它是开源的,但代码很复杂,所以我仍然不知道如何做到这一点。
我想要的是这个:

  • 运行一些生成 Markdown 文件的命令行语句
  • 运行一些代码来“发布”这个
  • 将其附加到 Github Actions 中的摘要
  • 很高兴我公司的每个人都可以看到工作流程附带的结果

  • Screenshot of GitHub Actions run result

    最佳答案

    它使用 GitHub API 到 create a check run .POST https://api.github.com/repos/{owner}/{repo}/check-runs创建或更新检查运行时,您可以指定 output请求正文中的参数。行动dotnet-tests-report使用 output 的 text 属性报告参数:


    输出对象的属性
    描述

    title (字符串)
    必需的。 检查运行的标题。
    summary (字符串)
    必需的。 检查运行的摘要。该参数支持 Markdown。
    text (字符串)
    检查运行的详细信息。该参数支持 Markdown。
    annotations (对象数组)
    将分析中的信息添加到特定代码行。注释在 GitHub 上的拉取请求的检查和文件更改选项卡中可见。 Checks API 将每个 API 请求的注释数量限制为最多 50 个。要创建超过 50 个注释,您必须向 Update a check run 发出多次请求。端点。每次更新检查运行时,注释都会附加到检查运行已存在的注释列表中。关于如何在 GitHub 上查看注释的详细信息,请参见“About status checks”。见 annotations object关于如何使用该参数的详细说明。
    images (对象数组)
    将图像添加到 GitHub 拉取请求 UI 中显示的输出。见 images object详细说明。


    看 Action 代码:https://github.com/zyborg/dotnet-tests-report/blob/237826dc017f02ebf61377af95d1a12f8409a527/action.ps1#L133-L149

    $url = "https://api.github.com/repos/$repoFullName/check-runs"
    $hdr = @{
    Accept = 'application/vnd.github.antiope-preview+json'
    Authorization = "token $ghToken"
    }
    $bdy = @{
    name = $report_name
    head_sha = $ref
    status = 'completed'
    conclusion = $conclusion
    output = @{
    title = $report_title
    summary = "This run completed at ``$([datetime]::Now)``"
    text = $reportData
    }
    }
    Invoke-WebRequest -Headers $hdr $url -Method Post -Body ($bdy | ConvertTo-Json)

    关于github-api - 如何将 Markdown 页面附加到 GitHub 操作工作流运行摘要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67507373/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com