Is the failing check on your PR also broken on main? How to check the default branch first
The job that broke on your branch might already be broken on main. Before you re-run it or dig through your own diff, look at the latest runs of the same workflow on the default branch. If main is red on the same job, the failure probably came with the code you branched from, not with your change.
You can check this from the GitHub CLI, from the REST API, or from the workflow's status badge. Here's how each one works, and the catch with each.
Why main is the first thing to check
A red check on your pull request is about your branch. What you actually want to know is whether the same job fails without your change. If the default branch fails the same way, your diff is probably not the cause, and re-running your branch is unlikely to help.
If main is green on that job, the failure is either yours or intermittent. That's when you open the log and look at the history of that one job. Checking main first can save you from debugging somebody else's breakage.
Check main from the terminal with gh
Start with gh run list. Its manual lists the filters you need: --branch will "Filter runs by branch", --workflow will "Filter runs by workflow", and --status will "Filter runs by status". The status values it lists include "cancelled|failure|neutral|skipped".
gh run list --branch main --workflow <your-workflow>
gh run list --branch main --workflow <your-workflow> --status failureLook at the newest runs. If the same workflow failed on main recently, open that run and compare its failing job with yours. Same job, same step, same error? Then it's probably not your change.
You can read the failure from the terminal too. gh run view has --log-failed, which will "View the log for any failed steps in a run or specific job". If someone re-ran it, --attempt takes "The attempt number of the workflow run", so you can pick which attempt you're looking at.
gh run view <run-id> --log-failedFor your own side, gh pr checks will "Show CI status for a single pull request." The gh run list manual points you there too: "To see runs associated with a pull request, users should run" gh pr checks. Add --required if you only care about the required ones: it will "Only show checks that are required".
Compare the exact commit, not just the branch
Main moves. A failure on main from this morning might be fixed by now, and a green run on main might be newer than the commit you branched from. When you can, compare against the main commit your branch is based on.
gh run list has --commit, which will "Filter runs by the SHA of the commit". Pass the SHA of the main commit your branch started from and you'll see whether that exact commit was already red. If it was, rebasing onto a newer, green main may be the whole fix.
gh run list --commit <sha-of-the-main-commit>Query the REST API when you want it in a script
If you want this check in a bot or a script, the REST API has a list endpoint for each workflow. This is the path on the GitHub docs page:
/repos/{owner}/{repo}/actions/workflows/{workflow_id}/runsFor workflow_id, "You can also pass the workflow file name as a string." Then filter. The branch parameter "Returns workflow runs associated with a branch. Use the name of the branch of the push." The status parameter "Returns workflow runs with the check run status or conclusion that you specify." And head_sha "Only returns workflow runs that are associated with the specified head_sha."
The catch is in the branch wording: it's the name of the branch of the push. If you want to narrow results to one trigger, add the event parameter too, which "Returns workflow run triggered by the event you specify."
Two more things from the docs. With certain filter parameters, "This endpoint will return up to 1,000 results for each search when using the following parameters:", so don't expect the full history from one filtered query. And on access: "Anyone with read access to the repository can use this endpoint." For private repositories, "OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository."
Glance at the workflow status badge
If the README already shows an Actions badge, it gives you a quick first answer. "A status badge shows whether a workflow is currently failing or passing." And "By default, badges display the status of your default branch."
Here's the part that's easy to miss: "If there are no workflow runs on your default branch, it will display the status of the most recent run across all branches." If the workflow never ran on main, the badge can show you another branch's result. It also reports on the workflow as a whole, not on the one job that failed on your branch.
There's no badge in the README? You can build the URL yourself. "You can build the URL for a workflow status badge using the name of the workflow file:"
https://github.com/OWNER/REPOSITORY/actions/workflows/WORKFLOW-FILE/badge.svgThe same page says: "To display the status of a workflow run for a specific branch, add" a branch parameter to the badge URL. That helps when your default branch isn't the one you merge into.
What to do with the answer
- Main fails on the same job: the failure came before your change. Look for an open issue or a fix in progress, then rebase once main is green. Don't burn re-runs on it.
- Main is green and the job fails only on your branch: read the failing log first. Your change is the main suspect.
- Main is green, but this job has failed and then passed on the same commit before: that's the flaky pattern. Read the log anyway. A flaky history isn't proof that this run is a flake.
- Too few runs on main to tell: treat it as a real failure until the log says otherwise.
Getting the answer on the pull request page
If you run this check a lot, we built FlakeRadar for it. It's a free Chrome extension that labels each failing GitHub Actions job on a pull request. One of its labels is Also failing on the default branch. The others are Known flake, New failure and Not enough history.
It reads the repository's own Actions history from your browser, with a GitHub token you create and keep on your device. Each label comes with counts, a time window and a date. Checks from other CI systems are not analysed, and FlakeRadar is not affiliated with or endorsed by GitHub. The gh and API checks above work fine without it.
Sources
- GitHub CLI manual for gh run list
- GitHub CLI manual for gh run view
- GitHub CLI manual for gh pr checks
- GitHub REST API reference for workflow runs
- GitHub Docs guide to adding a workflow status badge
Questions
If main is green, did my change break the job?
Not for sure. It means the job passes without your change, at least in the runs you looked at. Read the failing log first. The job could also fail now and then on its own.
Can I check main's runs on a private repository?
Yes, if your token can read the repository. GitHub's REST docs say anyone with read access to the repository can use the list endpoint. OAuth app tokens and classic personal access tokens need the repo scope for a private repository.
Why does the status badge show a result from another branch?
If there are no workflow runs on your default branch, the badge shows the status of the most recent run across all branches. Add a branch parameter to the badge URL to pin it to one branch.
How do I read the failed attempt on main if someone re-ran it?
Use gh run view with --attempt and the attempt number, plus --log-failed to see the log for the failed steps.
Related
- How to see the failed attempt after you re-run a GitHub Actions job
- Fine-grained token permissions to read GitHub Actions runs (and re-run them)
- Does re-running a GitHub Actions job pick up the latest main? Why your PR is still red
- How to re-run a failed GitHub Actions job with debug logging (web and gh CLI)