9

I'm trying to get familiar with Github Actions. I have configured my workflow in a way, that every time I push my code to GitHub, the code will automatically be built and pushed to heroku.

How can I access the build log information in terminal without going to github.com?

riQQ
  • 9,878
  • 7
  • 49
  • 66
do-it-yourself
  • 195
  • 1
  • 2
  • 9

2 Answers2

7

With the latest cli/cli tool named gh (1.9.0+), you can simply do
(from your terminal, without going to github.com):

gh run view <jobId> --log 
# or
gh run view <jobId> --log-failed

See "Work with GitHub Actions in your terminal with GitHub CLI"

With the new gh run list, you receive an overview of all types of workflow runs whether they were triggered via a push, pull request, webhook, or manual event.

To drill down into the details of a single run, you can use gh run view, optionally going into as much detail as the individual steps of a job.

For more mysterious failures, you can combine a tool like grep with gh run view --log to search across a run’s entire log output.

If --log is too much information, gh run --log-failed will output only the log lines for individual steps that failed.
This is great for getting right to the logs for a failed step instead of having to run grep yourself.

And with GitHub CLI 2.4.0 (Dec. 2021), gh run list comes with a --json flag for JSON export.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

Use

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

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

This will return a JSON with the following structure:

{
  "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": {...}
  ]
}

Access the jobs_url with a PAT that has repository admin rights.

riQQ
  • 9,878
  • 7
  • 49
  • 66