Lesson 1 of 9 · 22m
Workflow Anatomy: Events, Jobs, and the Execution Model
What actually happens after a push reaches GitHub, how jobs are scheduled, and why small mental model mistakes create confusing CI behavior.
GitHub Actions looks simple because the first example is twenty lines of YAML. Then somebody adds a matrix, a path filter, a pull request trigger, and a deployment job, and suddenly everyone is debugging by pushing empty commits. The fix is not more YAML snippets. It is a correct execution model.
A workflow run is a snapshot, not a live script
When an event matches, GitHub creates a run from the workflow file as it exists at the triggering commit. Editing the YAML after the run starts does not change that run. For pull_request, the tested commit is normally a merge commit synthesized from the pull request head and base branch.
name: build
on:
push:
branches: [main]
paths: ["services/api/**", ".github/workflows/build.yml"]
pull_request:
branches: [main]
permissions: {contents: read}
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm testThree things matter here. on selects events, permissions constrains the default token, and jobs.test is an independent unit of work scheduled onto a runner. Steps inside a job share a machine and working directory. Jobs do not.
Jobs are isolated unless you connect them
A job gets a clean runner, environment, and filesystem. If build creates dist/server.js, deploy cannot see it unless you transfer it or rebuild it. This surprises people because steps feel continuous while jobs are actually separate machines.
- uses: actions/upload-artifact@v4
with:
name: web-dist
path: dist/
retention-days: 3
# in the downstream job:
- uses: actions/download-artifact@v4
with:
name: web-dist
path: dist/needs creates ordering and dependency metadata. It does not transfer files. Artifacts transfer files.
Trigger filters are evaluated before YAML intuition
paths filters mean "at least one changed file matches." They are convenient, but they are not a dependency graph. If services/api imports packages/protocol, an API-only filter misses changes that can break the API. Path filters are a cost optimization, not a correctness mechanism.
Also remember that pull_request and push can both fire when a pull request branch is updated. Teams often "fix" duplicate CI by adding if conditions everywhere; usually the right fix is deciding which event owns which workflow.
Field notes
- Read the run header before reading logs: event, ref, SHA, actor, and workflow file version explain half of weird behavior.
workflow_dispatchinputs are strings unless you use typed inputs; validate them before using them in shell commands.- A job-level
ifcan avoid runner allocation; a step-levelifstill pays for checkout and setup. - Small workflows fail faster than one giant workflow. Split by ownership and trigger, not by mood.
Was this lesson helpful?