Tracking down every GitHub Actions workflow run triggered for a single commit starts with filtering by its SHA. Run gh run list with -c or --commit in GitHub CLI, or filter the workflow runs REST endpoint with head_sha.

Use gh run list in your terminal when you want CLI flags or jq filtering, or query the workflow runs REST endpoint when a script needs head_sha parameters. From the matching runs, you can inspect attempts and jobs, view or download logs, and re-run a job with its dependent jobs.

Filter workflow runs by commit SHA with GitHub CLI

In your terminal, gh run list lists recent workflow runs for a repository. Pass -c or --commit to filter those runs by the SHA of the commit.

If a commit triggers multiple runs, pair --commit with other gh run list flags. You can also pass --json to output JSON with the specified fields.

  • Pass -b or --branch to filter runs by branch.
  • Pass -e or --event to filter runs by which event triggered the run.
  • Watch out if you pass -w: it will not fetch disabled workflows, so add -a or --all to include disabled workflows.
  • Pass -L or --limit to set the maximum number of runs to fetch.
  • Pass -q or --jq to filter JSON output using a jq expression.

Here's the catch with ruleset workflows. Runs created by organization and enterprise ruleset workflows will not display a workflow name due to GitHub API limitations. Filter by -c or -b instead of relying on the workflow name. Also, if you want to see runs associated with a pull request, run gh pr checks instead.

Query workflow runs by commit SHA with the REST API

If you need run data in a script or tool, use the workflow runs REST endpoint. It lists all workflow runs for a repository, and you can use parameters to narrow the list of results.

Pass the head_sha query parameter to return only workflow runs associated with the specified SHA. You can also pass branch to return workflow runs associated with a branch, or event to return workflow runs triggered by the specified event.

Two more query parameters help narrow busy repositories. Use status to filter by check run status or conclusion, and use created to filter workflow runs within a date-time range. The per_page parameter accepts up to 100 results per page.

There is a ceiling to watch for here. When you use filter parameters on the list workflow runs endpoint, it returns up to 1,000 results for each search. Combine filters like head_sha, branch, and status if your query gets close to that limit.

Anyone with read access to the repository can use the list workflow runs endpoint. Public repository resources can be requested without authentication or token permissions. On private repositories, a fine-grained token needs Actions repository permissions (read).

Inspect run attempts, jobs, and logs for that commit

GitHub Actions uses the Checks API to output statuses, results, and logs for a workflow. GitHub creates a new check suite for each workflow run. That check suite contains a check run for each job in the workflow, and each job includes steps.

When you want the breakdown inside a run, use the attempt jobs endpoint to list jobs for a specific workflow run attempt. You can pass parameters there to narrow the list of results. If you want one job, the get job endpoint gets a specific job in a workflow run.

To check logs from your terminal, run gh run view with the run ID or job ID.

gh run view RUN_ID --log gh run view --job JOB_ID --log-failed 

The first command views logs for a workflow run, and the second filters logs for failed steps. Over the REST API, the job logs endpoint returns a redirect URL to download a plain text file of logs for a workflow job. That link expires after 1 minute, so fetch it right away. If you only want one step, the step logs endpoint retrieves logs for one step.

Two log behaviors are easy to miss when you debug a failure. First, you must be logged in to a GitHub account to view workflow run information, including for public repositories. Second, failed steps are automatically expanded in workflow run logs, and searching logs only includes expanded steps. You also need read access to the repository to search logs.

Partial re-runs have a catch too. When you download the log archive for a workflow that was partially re-run, the archive only includes the jobs that were re-run. To get a complete set of logs for jobs that were run from that workflow, download the log archives for the previous run attempts that ran the other jobs.

If you re-run a job, it re-runs the job and its dependent jobs in a workflow run. Doing that with a fine-grained token requires Actions repository permissions (write).

Check whether a red PR job is a known flake

If you're staring at a red pull request check, it helps to know whether that job failed and then passed on the same commit before, or is a new failure. You can check run history with the CLI and REST API above, or check it right on the pull request.

We built FlakeRadar, a Chrome extension for GitHub pull requests, as one option for that check. Open a pull request with a red check and click FlakeRadar, and it reads the repository's own GitHub Actions history to give each failing GitHub Actions job a label: Known flake, New failure, Also failing on the default branch, or Not enough history. It only analyses GitHub Actions jobs.

Each label comes with counts, a time window, and a date—for example, failed then passed on the same commit on 4 of 120 commits on main in the last 30 days. Everything runs in your browser against api.github.com with a fine-grained personal access token kept on your device, with no CI config changes, no secrets added to CI, and no analytics or telemetry.

The Free plan ($0) covers labels for failing checks on public repositories, 30 days of history, and one-click re-run if you turn it on. The Pro plan ($19/month) includes everything in Free, plus private repositories, 90 days of history, pinned repositories, a refresh button, and alerts. One-click re-run stays off until you enable it in settings with a token that has Actions: Read and write, and it sends a re-run only when you click.

Sources

Frequently Asked Questions

Why is the workflow name blank for some runs in gh run list?

Runs created by organization and enterprise ruleset workflows will not display a workflow name due to GitHub API limitations. Filter by commit SHA (-c or --commit) or branch (-b or --branch) instead.

Why are some jobs missing when I download logs after a re-run?

When you download the log archive for a workflow that was partially re-run, the archive only includes the jobs that were re-run. Download the log archives from the previous run attempts to get logs for the remaining jobs.

Do I need a token to list workflow runs for a commit SHA on a public repository?

The list workflow runs endpoint can be used without authentication or token permissions if only public resources are requested. For private repositories, a fine-grained token needs Actions repository permissions (read).

If a job failed and then passed on the same commit before, is it safe to ignore?

No. A Known flake label means the same job has failed and then passed on one commit before, which is evidence rather than a promise. If the failure matters, read the log.

Originally published on Bright Labs.