cli icon indicating copy to clipboard operation
cli copied to clipboard

Ability to view specific job's step logs

Open dlvhdr opened this issue 6 months ago • 5 comments

Describe the feature or problem you’d like to solve

Currently the gh cli allows you to view a job's logs with:

gh run view -R neovim/neovim --log --job=43904694235

This fetches the entire output of the job.

I would like the ability to only view logs of a specific step of the job.

The GitHub UI does fetch a specific step logs by calling:

https://github.com/neovim/neovim/commit/7935cf4f7f35150d3c04e719938046d4cfa8f905/checks/43904694235/logs/2

This endpoint is not exposed by the GitHub API.

Proposed solution

I would imagine something like:

gh run view -R neovim/neovim --log --job=43904694235 --step=3

An alternative solution would be to solve https://github.com/orgs/community/discussions/41351 which would add more accurate timestamps to a step's startedAt and completedAt. This would allow me to correlate the steps logs from the full job logs.

Additional context

I would like to build a UI similar to github's job page. The page allows the user to expand the different steps of the job, and see only the correlated logs.

dlvhdr avatar Jun 21 '25 12:06 dlvhdr

Hey @dlvhdr,

When you run gh run view -R neovim/neovim --log --job=43904694235 the second column in most cases should contain the step name that you could filter on but I see that specific example reports UNKNOWN STEP. We have a few open issues with the actions team about resolving this. I don't think it would be tremendously hard to add --step but just curious if you would still need that if the step was correctly reported in the log output and you could grep it. Helps us prioritise!

williammartin avatar Jun 21 '25 15:06 williammartin

Hey @williammartin, this would definitely help!

But, currently, I haven't seen a case where the step is different than UNKNOWN STEP. I've checked various repos and jobs and always get only these.

e.g. running:

$ gh run view -R cli/cli --log --job=44507380755 | awk -F '\t' '{print $2}' | uniq
UNKNOWN STEP

In other cases, gh fails to find the logs because of https://github.com/cli/cli/issues/11059

dlvhdr avatar Jun 21 '25 15:06 dlvhdr

Got it, yes any time we see UNKNOWN STEP it's a result of the log service having been changed underneath the CLI. All the reports of this being a problem are useful to us getting the prioritised so thanks for opening this up. Vaguely recall that it most commonly occurs after some period of time and if you get the logs shortly after the run, the steps will be there.

williammartin avatar Jun 21 '25 19:06 williammartin

Catching up on this conversation, I believe CLI maintainers need to collaborate with Actions team on a more accurate solution than slicing job logs by timestamp.

The GitHub UI does fetch a specific step logs by calling:

https://github.com/neovim/neovim/commit/7935cf4f7f35150d3c04e719938046d4cfa8f905/checks/43904694235/logs/2

This endpoint is not exposed by the GitHub API.

An alternative solution would be to solve https://github.com/orgs/community/discussions/41351 which would add more accurate timestamps to a step's startedAt and completedAt. This would allow me to correlate the steps logs from the full job logs.

I think the API challenges in this issue are due the larger check suites and runs framework that GitHub Actions workflow runs and jobs are built on, which doesn't have any concept that maps to GitHub Actions workflow run steps.

So I imagine the GitHub Actions logs are stored as a whole, which would require an API endpoint that could parse the logs for clients to return the step specific portion.

Ideally, it would be nice if the log file contained metadata denoting the separate steps.

andyfeller avatar Jun 23 '25 13:06 andyfeller

Just to help clarify, adding a --step flag would not solve my issue entirely. Some of of the steps in our company's CI are huge and contain 20K lines. Fetching the entire run can take upwards of 20 seconds. I would like to avoid fetching these steps and doing something similar to the github website where it can fetch only a specific step's logs. E.g. https://github.com/neovim/neovim/commit/7935cf4f7f35150d3c04e719938046d4cfa8f905/checks/43904694235/logs/2

dlvhdr avatar Dec 10 '25 17:12 dlvhdr