如何将降价页面附加到 GitHub Actions 工作流程运行摘要?
Posted
技术标签:
【中文标题】如何将降价页面附加到 GitHub Actions 工作流程运行摘要?【英文标题】:How to attach a markdown page to GitHub Actions workflow run summary? 【发布时间】:2021-08-03 00:53:30 【问题描述】:The GitHub Action "dotnet-tests-report" 将带有测试结果的降价页面附加到 Github Action 工作流运行摘要。这真是太好了。工作流程完成后,结果会立即变得清晰。以视觉方式清晰。
它是开源的,但是代码很复杂,所以我还是不知道怎么做。
我想要的是这个:
-
运行一些命令行语句来生成降价文件
运行一些代码来“发布”这个
将其附加到 Github Actions 中的摘要中
很高兴我公司的每个人都可以看到附加到工作流的结果
【问题讨论】:
【参考方案1】:在寻找类似的解决方案时,我发现现在有一个可用的操作: https://github.com/LouisBrunner/checks-action,
它实际上使您免于编写请求,甚至允许提供降价文件,如下所示:
- name: Create CheckRun for code Coverage
uses: LouisBrunner/checks-action@v1.2.0
with:
token: $ secrets.GITHUB_TOKEN
name: Code Coverage
conclusion: $ job.status
output: "\"summary\":\"Code Coverage\""
output_text_description_file: coveragereport/Summary.md
【讨论】:
修正output
参数,应该是output: "\"summary\":\"Code Coverage\""
谢谢,@igagis - 已修复。【参考方案2】:
它使用 GitHub API 来create a check run。
POST https://api.github.com/repos/owner/repo/check-runs
创建或更新检查运行时,您可以在请求正文中指定output
参数。操作dotnet-tests-report
使用报告的output
参数的文本属性:
Properties of the output object | Description |
---|---|
title (string) |
Required. The title of the check run. |
summary (string) |
Required. The summary of the check run. This parameter supports Markdown. |
text (string) |
The details of the check run. This parameter supports Markdown. |
annotations (array of objects) |
Adds information from your analysis to specific lines of code. Annotations are visible on GitHub in the Checks and Files changed tab of the pull request. The Checks API limits the number of annotations to a maximum of 50 per API request. To create more than 50 annotations, you have to make multiple requests to the Update a check run endpoint. Each time you update the check run, annotations are appended to the list of annotations that already exist for the check run. For details about how you can view annotations on GitHub, see "About status checks". See the annotations object description for details about how to use this parameter. |
images (array of objects) |
Adds images to the output displayed in the GitHub pull request UI. See the images object description for details. |
查看操作代码: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 Actions 工作流程运行摘要?的主要内容,如果未能解决你的问题,请参考以下文章
如何将 GitHub Actions 与多个存储库一起使用并部署到 GitHub Pages?