Intro to GitHub Actions (CI/CD)
Stop running tests by hand. By the end of this lesson you'll write a workflow YAML file that runs your test suite automatically on every push and pull request — your first taste of continuous integration, built right into GitHub.
Learn Intro to GitHub Actions (CI/CD) in our free Git course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…
Part of the free Git course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
What You'll Learn
1️⃣ Your First Workflow
A workflow is a YAML file in .github/workflows/ . This one runs your tests on every push to main and on every pull request. Commit it, push, and the run shows up in the repo's Actions tab.
2️⃣ The Anatomy of a Workflow
Every workflow shares the same skeleton: name , the triggering events under on , and jobs . Each job sets runs-on (the runner) and a list of steps . A step either uses a prebuilt action or run s shell commands.
3️⃣ Testing Across Versions (Matrix)
A matrix runs the same job several times in parallel — once per value you list. It's the standard way to prove your code works on multiple language versions at once, with one small block of YAML.
Your turn. Complete a minimal CI workflow. Fill in the three blanks, then commit it as .github/workflows/ci.yml .
Common Errors (and the fix)
- Workflow never runs: the file must be in .github/workflows/ (exact path) and end in .yml / .yaml . Check the path and that you pushed it.
- "Invalid workflow file": YAML is indentation-sensitive — use spaces, not tabs, and keep keys aligned. The Actions tab shows the exact line.
- Steps fail with "file not found": you forgot actions/checkout . The runner is empty until you check out your code first.
- "command not found" (e.g. npm): the tool isn't installed on the runner. Add a setup action like actions/setup-node before using it.
- Trigger never fires: your on: branches don't match. If you push to dev but only listed main , nothing runs.
Pro Tips
- 💡 Pin action versions: use @v4 tags so a surprise update doesn't break your build.
- 💡 Start from a template: the Actions tab suggests starter workflows for your language.
- 💡 Cache dependencies: setup actions often have a cache option to speed up runs.
- 💡 Add a status badge: drop the workflow's badge in your README so the build status is visible.
📋 Quick Reference
YAML key
Purpose
name:
Label shown in the Actions tab
on:
Events that trigger the workflow
jobs:
One or more jobs to run
runs-on:
The runner OS for a job
uses:
Pull in a reusable action
run:
Execute shell commands
Frequently Asked Questions
Mini-Challenge: Add CI to a Project
No file given this time — just the plan. Wire up real continuous integration and watch it pass, then fail.
🎉 Lesson Complete!
- ✅ GitHub Actions is built-in CI/CD driven by YAML workflows
- ✅ Workflows live in .github/workflows/
- ✅ on sets triggers; jobs run on a runs-on runner with steps
- ✅ uses pulls a Marketplace action; run executes commands
- ✅ actions/checkout is the usual first step
- ✅ Next lesson: manage nested repositories with submodules and monorepos
Practice quiz
What is GitHub Actions?
- A code editor
- A merge strategy
- GitHub's built-in CI/CD system that runs workflows on events
- A branch type
Answer: GitHub's built-in CI/CD system that runs workflows on events. GitHub Actions automates building, testing, and deploying code in response to repository events.
Where must workflow files live in your repo?
- In .github/workflows/
- In the repo root
- In .git/hooks/
- In /actions/
Answer: In .github/workflows/. Workflow YAML files go in the .github/workflows/ directory of your repository.
What format are workflow files written in?
- JSON
- TOML
- XML
- YAML
Answer: YAML. GitHub Actions workflows are YAML files (.yml or .yaml).
What does the top-level 'on:' key define?
- The operating system
- The events that trigger the workflow (e.g. push, pull_request)
- The output
- The owner
Answer: The events that trigger the workflow (e.g. push, pull_request). 'on' lists the events — like push or pull_request — that start the workflow.
What is a 'job' in a workflow?
- A set of steps that run on one runner machine
- A single command
- A commit
- A secret
Answer: A set of steps that run on one runner machine. A job groups steps that execute together on a runner; jobs can run in parallel by default.
What does 'runs-on: ubuntu-latest' specify?
- The programming language
- The branch
- The runner (virtual machine) the job executes on
- The schedule
Answer: The runner (virtual machine) the job executes on. runs-on chooses the runner OS/image, such as ubuntu-latest, for that job.
What does the 'uses:' keyword in a step do?
- Runs a shell command
- Pulls in a reusable action (e.g. actions/checkout@v4)
- Sets an environment variable
- Declares a job
Answer: Pulls in a reusable action (e.g. actions/checkout@v4). 'uses' references a prebuilt action from the Marketplace or a repo, like actions/checkout.
What does the 'run:' keyword do in a step?
- Imports an action
- Triggers the workflow
- Creates a job
- Executes shell commands on the runner
Answer: Executes shell commands on the runner. 'run' executes shell commands directly, e.g. run: npm test.
Why is actions/checkout usually the first step?
- It deploys the app
- It checks out your repository code onto the runner so later steps can use it
- It installs Node
- It opens a PR
Answer: It checks out your repository code onto the runner so later steps can use it. The runner starts empty, so actions/checkout fetches your code before tests can run.
Where do you find reusable, prebuilt actions?
- The Issues tab
- The Wiki
- The GitHub Marketplace
- The Releases page
Answer: The GitHub Marketplace. The GitHub Marketplace hosts thousands of prebuilt actions you reference with 'uses'.
Continue this course
- Previous: Forking & Contributing to Open Source
- Next: Submodules & Monorepos