Sub topic 14
Reproducing a Failure Outside Actions
This chapter assumes you can read a failed run's log, find the first real error, and use basic shell commands. It also assumes you have the failing repository cloned and Node.js installed. The examples use the app/ workflow from earlier chapters.
Why reproduce locally
Each push to fix a workflow costs a full run: queue time, setup, and the failure itself. A local reproduction gives you a loop of seconds. It also separates two questions: "is my code wrong?" and "is the runner environment different from mine?"
Match the runner's conditions
A run starts from a clean checkout on a fresh machine. Your laptop has leftovers: installed packages, cached builds, and environment variables. To reproduce a failure, copy what the log shows.
Collect these from the log and workflow file:
- The commit SHA the run used (shown in the run summary).
- The tool versions, such as
node-version: 20in the setup step. - The working directory for each
runstep. - The environment variables set under
env:. - The exact commands, in order.
The script below follows the workflow's steps in a fresh clone. It starts from a clean directory so stale files cannot hide the problem.
#!/usr/bin/env bash
set -euo pipefail
REPO_URL="${1:?usage: repro.sh <repo-url> <commit-sha>}"
SHA="${2:?usage: repro.sh <repo-url> <commit-sha>}"
WORKDIR="$(mktemp -d)"
git clone "$REPO_URL" "$WORKDIR/repo"
cd "$WORKDIR/repo"
git checkout "$SHA"
node --version # compare with the version in the log
cd app # the working-directory from the workflow
npm ci
npm testset -euo pipefail makes the script stop at the first failing command. This matches how Actions treats a run step on Linux, where the default bash shell runs with -e and -o pipefail.
Decide where the difference is
If the failure does not reproduce, the cause is usually one of these:
| Difference | Typical sign in the log |
|---|---|
| Tool version | Syntax or API errors that your version accepts |
| Operating system | Case-sensitive path errors, missing commands |
| Environment variable | Code takes a different branch when `CI=true` |
| Secret or token | Authentication errors that cannot occur locally |
| Stale local files | Passes locally only because of `node_modules` or build output |
Setting CI=true locally is often worth trying. Many tools, including test runners, change their behavior when it is set.
CI=true npm testRunning the workflow itself with act
The open-source tool act runs workflow jobs in Docker containers on your machine. It reads the files in .github/workflows/.
# List the jobs act can see
act -l
# Run the "test" job as a pull_request event
act pull_request -j testact is an approximation. Its default images are smaller than GitHub's hosted runners, some actions behave differently, and it does not have your repository secrets. Use it to check workflow syntax and step order. Use the clean-clone script to check your code.
Close the loop
Once you can reproduce the failure, change one thing at a time and re-run. When the local run passes, push the fix and check the new Actions run, as described in the previous chapter.
Exercise
Your workflow's npm test step fails on the runner with a "module not found" error for ./Utils. The same command passes on your macOS laptop. Name one likely cause and one way to reproduce it locally.
Show answer
The runner uses Linux, whose file system is case-sensitive, while macOS usually is not. The file is probably named utils.js but imported as ./Utils. To reproduce it, run the tests in a Linux environment such as a Docker container or act, or check the import against the real file name with git ls-files.