Sub topic 1
How a workflow run is organized
This chapter covers the structure of a GitHub Actions run. You need this model before you can read a log. A log is organized by the same units that the workflow file defines, so knowing them tells you where to look when something goes wrong.
Prerequisites
This chapter assumes you have:
- Basic Git and GitHub usage: commits, pushes, and pull requests.
- The ability to read YAML, including nested mappings and lists.
- Familiarity with running commands in a shell.
- A repository with at least one GitHub Actions workflow, or the willingness to add the example below.
You do not need to have debugged a failing run before. That is what the rest of this tutorial covers.
The four levels: workflow, job, step, runner
A GitHub Actions run has a fixed hierarchy. Each level has its own place in the YAML file and its own place on the run page.
| Level | What it is | Where it appears in YAML |
|---|---|---|
| Workflow | A YAML file in `.github/workflows/` that describes an automated process | The whole file |
| Event | The trigger that starts a run, such as a push or a pull request | `on:` |
| Job | A group of steps that run together on one machine | An entry under `jobs:` |
| Runner | The machine, virtual or physical, that executes a job | `runs-on:` |
| Step | One unit of work inside a job: a shell command or an action | An entry under `steps:` |
A workflow run is one execution of a workflow. It is created each time an event matches the on: filter. Re-running a workflow creates a new attempt of the same run. It does not create a new run.
Jobs and runners
Each job gets a fresh runner. Two jobs in the same workflow do not share a file system, installed tools, or environment variables. If job B needs something that job A produced, you must pass it explicitly, for example with artifacts or job outputs.
By default, jobs run in parallel. The needs: key makes one job wait for another. If a job listed in needs: fails, the dependent job is skipped by default.
Steps
Steps run in order, one after another, on the job's runner. They share the runner's file system. Environment changes made through GITHUB_ENV and GITHUB_PATH carry over to later steps. A plain export inside a run: step does not, because each run: step starts its own shell process.
A step is one of two kinds:
- A
run:step runs a command in a shell. - A
uses:step runs an action, which is a reusable unit of code such asactions/checkout@v4.
A baseline workflow
The workflow below has one job and four steps. The rest of this tutorial uses it as a baseline.
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm testRead it top to bottom:
name: CIis the workflow name shown in the Actions tab.on: [push, pull_request]starts a run on every push and on pull request activity.- The job
testruns on a GitHub-hosted Ubuntu runner. - The first step checks out the repository onto the runner.
- The second step installs Node.js 20.
- The third step installs dependencies from
package-lock.jsonwithnpm ci. - The fourth step runs the project's tests.
The steps have no name: key. GitHub then generates a label from the step content, such as Run npm ci. Setting a name: makes the run page easier to scan, and you will see the difference when you read logs.
How the run is laid out
The diagram shows how one event expands into the units you will see on the run page.
Why this structure matters for debugging
Every failure belongs to exactly one step, and every step belongs to exactly one job. This gives you a fixed path when you debug:
- Find the run that failed.
- Find the job in that run that failed.
- Find the first step in that job that failed.
- Read the log for that step.
The next chapters turn this path into practice. For now, note two properties that make the path reliable.
First, a step fails when its command exits with a non-zero code, or when an action reports failure. Second, when a step fails, the remaining steps in that job are skipped by default. They are not failures. They simply did not run. This is why a log with many red or grey entries usually has only one real cause, and it sits at the earliest failure.
Example: a failure in the wrong directory
Suppose package.json is not at the repository root but in a subdirectory named app/. The baseline workflow then fails at step 3.
checkoutsucceeds. The files are on the runner.setup-nodesucceeds. Node.js is installed.npm cifails. It looks forpackage.jsonin the current directory, which is the repository root, and finds none.npm testis skipped because an earlier step failed.
The job is marked failed, and the run is marked failed. The failing step is npm ci, but the underlying mistake is a wrong working directory. The step name tells you where the failure surfaced. It does not always tell you why.
Fixing the example
The fix tells run: steps to execute inside app/. It also points the npm cache at the lock file in that directory.
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: app
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: app/package-lock.json
- run: npm ci
- run: npm testTwo details are easy to get wrong:
defaults.run.working-directoryapplies only torun:steps. It does not change whereuses:steps look for files. That is whycache-dependency-pathis set separately, and why its value is relative to the repository root (app/package-lock.json), not toapp/.cache: npmmakessetup-noderestore and save the npm cache. Without a correctcache-dependency-path, the action looks for a lock file at the repository root and the step can fail.
Runs, attempts, and what a re-run changes
Understanding identifiers saves time when you use the web interface or the gh CLI later.
- A run has a numeric run ID and a run number. The ID is unique across GitHub. The number counts runs of that workflow in your repository.
- A re-run keeps the same run ID but increases the attempt number.
- You can re-run all jobs or only the failed jobs. Re-running only failed jobs reuses the results of jobs that already passed.
A re-run uses the same commit and the same workflow file version as the original attempt. If you pushed a fix, a re-run will not pick it up. A push starts a new run. Keep this in mind when you verify a fix, because re-running an old attempt tests the old code.
Common mistakes at this level
- Assuming jobs share files. A file created in one job is not visible in another.
- Treating skipped steps as failures. Skipped means "did not run", and the cause is earlier in the job.
- Reading from the bottom of the log. The last red mark is often a follow-on effect. The first failure is usually the cause.
- Expecting
defaults.runto affectuses:steps. - Re-running an old attempt after pushing a fix.
Exercises
Exercise
A workflow has two jobs, build and deploy, and deploy declares needs: build. The build job fails at its third step. What is the state of the fourth step in build, and what is the state of deploy?
Show answer
The fourth step in build is skipped, because a step after a failed step does not run by default. The deploy job is skipped, because a job listed in needs: failed. Only the third step in build is the failure to investigate.
Exercise
You set defaults.run.working-directory: app on a job. A uses: actions/setup-node@v4 step with cache: npm still fails to find the lock file. Why, and what do you change?
Show answer
defaults.run.working-directory applies only to run: steps, so the setup-node action still looks at the repository root. Add cache-dependency-path: app/package-lock.json to the step's with: block.
Exercise
You push a fix to a failing workflow, then click "Re-run failed jobs" on the old run. The job fails with the same error. Give the most likely reason and the correct way to test the fix.
Show answer
A re-run uses the same commit and workflow file as the original attempt, so it does not include your fix. Push the commit to trigger a new run (or open a new pull request event), and read the log of that run.