GitHub Actions:如何通过 API 访问当前构建的作业日志?

问题描述 投票:0回答:1

我想通过nodejs后端从Github Actions获取当前工作流程的作业日志。我知道 Github 提供了一个 API,可以访问有关工作流程的信息,如下所示:

GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs

回复如下:

{
  "total_count": 1,
  "workflow_runs": [
    {
      "id": 30433642,
      "node_id": "MDEyOldvcmtmbG93IFJ1bjI2OTI4OQ==",
      "head_branch": "master",
      "head_sha": "acb5820ced9479c074f688cc328bf03f341a511d",
      "run_number": 562,
      "event": "push",
      "status": "queued",
      "conclusion": null,
      "workflow_id": 159038,
      "url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642",
      "html_url": "https://github.com/octo-org/octo-repo/actions/runs/30433642",
      "pull_requests": [],
      "created_at": "2020-01-22T19:33:08Z",
      "updated_at": "2020-01-22T19:33:08Z",
      "jobs_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/jobs",
      "logs_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/logs",
      "check_suite_url": "https://api.github.com/repos/octo-org/octo-repo/check-suites/414944374",
      "artifacts_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/artifacts",
      "cancel_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/cancel",
      "rerun_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/rerun",
      "workflow_url": "https://api.github.com/repos/octo-org/octo-repo/actions/workflows/159038",
      "head_commit": {...},
      "repository": {...},
      "head_repository": {...}
  ]
}

这个 stackoverflow 问题,我了解到您可以通过

job_url
获取有关当前构建日志的更多信息,但这是否是实时发生的?有没有办法流式传输当前日志,以便我能够在我自己的网页上显示它们?

背景: 我想使用 dispatch-event 通过 HTTP 请求触发工作流程,之后,我想在我自己的 UI 上显示当前作业日志

github continuous-integration github-actions github-api
1个回答
0
投票

确实可以在 GitHub API 端点

logs_url
的响应中找到
GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs/{run_id}
属性,它提供有关各个工作流程运行的详细信息。此 URL 指向包含整个工作流程运行的原始日志的存档,其中包括工作流程中执行的每个作业和步骤的日志。

但是,需要注意的是,无论存储库是公共的还是私有的,您都必须经过身份验证(通常通过个人访问令牌)才能访问 API 并从

logs_url
下载日志。

© www.soinside.com 2019 - 2024. All rights reserved.