DEV Community

Zane — 個人開発メモ
Zane — 個人開発メモ

Posted on

Debugging a failing GitHub Actions run from the failure itself

Debugging a failing GitHub Actions run from the failure itself

Most CI failures are read wrong. The red step name you see in the PR is usually the last thing that broke, not the cause. This is a short triage path for GitHub-hosted runners that gets you to the first real error instead of the loudest one.

1. Jump to the first failing step, not the failing job

gh run list --limit 5
gh run view <run-id> --log-failed
Enter fullscreen mode Exit fullscreen mode

--log-failed prints only the failed steps, which strips 90% of the noise. If you do not have gh installed, the same information is in the web UI under the failed step's log, but --log-failed is faster because it does not interleave passing steps.

2. Classify before you read

Four shapes cover almost everything:

Shape Typical line Real cause
Missing tool command not found: xcodebuild runner image changed, or the tool lives in a path the step does not see
Permission Permission denied (publickey) / 403 token scope or key not mounted in this step
Environment leak Cannot find module only in CI node_modules built on a different platform or a lockfile drift
Timeout step killed at N minutes real work exceeds the limit — check whether caching silently stopped working

The shape decides where you look. A command not found is never a code problem; a Cannot find module on a npm ci step is almost always lockfile or platform.

3. Confirm the runner image is what you think

- run: |
    sw_vers
    uname -m
    which xcodebuild || true
    echo "${PATH}"
Enter fullscreen mode Exit fullscreen mode

macos-latest moves. If a workflow started failing on a date with no code change, print the image version in the failing step and compare to the last green run. This single check explains a large share of "it broke overnight" reports.

4. Reproduce locally with the same toolchain

act runs workflows in Docker, which is useful for Linux jobs and useless for macOS ones. For macOS, the honest move is to reproduce the step command in a local shell with the same env:

# take the exact env block from the job, then run the failing command
env -i PATH="$PATH" HOME="$HOME" bash -lc '<failing command>'
Enter fullscreen mode Exit fullscreen mode

If it passes under env -i but fails in CI, the difference is the environment, not the code. That is a much smaller search space.

5. Only then touch the workflow

The temptation is to add set -x, continue-on-error, or a retry wrapper. Do that after you know the shape. continue-on-error on a failing step converts a hard failure into a silent one and is the most common way a CI suite stops being trustworthy.

What this does not fix

  • Flaky tests that fail on timing — those need quarantine, not retries
  • Secrets that exist in the repo settings but not in fork PRs (by design)
  • Cache poisoning: if a cached artifact is wrong, a clean run is the only honest baseline

Reading the log without leaving the terminal

One practical annoyance: the failure text is long, wrapped, and full of ANSI colour codes that make selecting the useful lines awkward. Stripping them first is worth the one line:

gh run view <run-id> --log-failed | sed -r 's/\x1B\[[0-9;]*[mK]//g' | less -R
Enter fullscreen mode Exit fullscreen mode

If you prefer to read what is already on screen (browser log view, local terminal), selecting the region and reading it in place — rather than copying wrapped text into a translator — keeps the indentation that tells you which stack frames belong together.

Links

CI debugging flow, direct download page:
https://www.zipp-mac.com/solutions/github-actions-ci-debugger/?utm_source=devto&utm_medium=article&utm_campaign=ci_wave13

Distribution page (BOOTH):
https://zipp-mac.booth.pm/items/9082185

Top comments (0)