GitHub Actions:如何通过终端访问当前构建的日志

do-*_*elf 9 build github github-actions

我正在尝试熟悉 Github Actions。我已经以某种方式配置了我的工作流程,每次我将代码推送到 GitHub 时,代码都会自动构建并推送到 heroku。

如何在不访问 github.com 的情况下在终端中访问构建日志信息?

Von*_*onC 8

使用名为(1.9.0+)的最新cli/cli工具gh,您只需执行
\n(从终端,无需转到github.com):

\n
gh run view <jobId> --log \n# or\ngh run view <jobId> --log-failed\n
Run Code Online (Sandbox Code Playgroud)\n

请参阅“使用 GitHub CLI 在终端中使用 GitHub Actions

\n
\n

通过新的gh run list,您可以概览所有类型的工作流运行,无论它们是通过推送、拉取请求、Webhook 还是手动事件触发的。

\n

要深入了解单次运行的详细信息,您可以使用gh run view,也可以选择深入了解作业的各个步骤的详细信息。

\n

对于更神秘的故障,您可以结合使用 grep 等工具来gh run view --log搜索 run\xe2\x80\x99s 的整个日志输出。

\n

如果--log信息太多,gh run --log-failed将仅输出失败的各个步骤的日志行。
\n这非常适合直接查看失败步骤的日志,而不必grep自己运行。

\n
\n

GitHub CLI 2.4.0(2021 年 12 月gh run list)附带--json用于 JSON 导出的标志。

\n


riQ*_*iQQ 2

使用

curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/<github-user>/<repository>/actions/workflows/<workflow.yaml>/runs
Run Code Online (Sandbox Code Playgroud)

https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs

这将返回具有以下结构的 JSON:

{
  "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": {...}
  ]
}
Run Code Online (Sandbox Code Playgroud)

jobs_url使用具有存储库管理员权限的 PAT访问。