GitHub Actions Basics
Every chapter so far has been manual — you decide when to test, when to check things work. GitHub Actions automates that: a workflow file describes steps to run automatically whenever something happens in your repo (a push, a PR, a schedule), and GitHub runs them on its own servers, for free on a generous tier for public repos and personal use.
The Core Concepts
.github/workflows/ describing what to run and when. A repo can have several, each independent.Your First Workflow — Running Tests on Every Push
Create .github/workflows/test.yml in your repository:
Reading it line by line:
- on: — runs on every push to main, and on every PR targeting main (catching problems before merge, not just after).
- runs-on: ubuntu-latest — GitHub spins up a fresh Ubuntu virtual machine for this job, every single run, with nothing left over from previous runs.
- actions/checkout@v4 — a pre-built action (published by GitHub itself) that clones your repo onto that fresh machine. Almost every workflow starts with this step.
- actions/setup-node@v4 — another pre-built action, installing the specified Node.js version. Equivalent actions exist for Python, Java, Go, and most other languages.
- run: npm install / npm test — ordinary shell commands, exactly as you'd type them locally.
Seeing It Run
Once committed and pushed, the workflow appears under the repository's Actions tab — every run shows live logs, step by step, and a pass/fail result.
The same result also shows directly on a PR's page as a status check — and if branch protection requires it to pass (Course 3, Chapter 6), a red ❌ here physically blocks the merge button until fixed.
A Second, Equally Common Workflow — Linting
Running a linter automatically catches the kind of style/consistency issues Chapter 7 flagged as not worth a human reviewer's time — letting Actions enforce that instead.
Command Reference — Concepts, Not Shell Commands
| YAML key | What it does |
|---|---|
| on: | Defines what event(s) trigger the workflow |
| jobs: | One or more independent sets of steps, run in parallel by default |
| runs-on: | Which virtual machine OS/image the job runs on |
| steps: | The ordered list of actions/commands within a job |
| uses: | Runs a pre-built action from the Marketplace or another repo |
| run: | Executes a raw shell command directly |
Chapter 8 Quick Reference
- Workflow files live in .github/workflows/, written in YAML
- on: defines the trigger (push, pull_request, schedule, and others)
- jobs → steps — each job runs on a fresh VM; steps run in order within it
- uses: runs a pre-built Marketplace action; run: runs a raw shell command
- actions/checkout@v4 is the near-universal first step — clones your repo onto the runner
- Results appear on the Actions tab and directly on PRs as status checks
- A failing workflow only reports — branch protection (Course 3, Ch6) is what actually enforces it blocking a merge
- Next chapter (Scenario): multiple users on the same branch — diverged history, force-push dangers, and branch protection rules