You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
GitHub Actions is GitHub's built-in CI/CD platform. It allows you to automate workflows directly from your repository — building, testing, and deploying code in response to events like pushes, pull requests, and releases.
| Concept | Description |
|---|---|
| Workflow | A YAML file in .github/workflows/ that defines automation |
| Event | A trigger that starts a workflow (push, PR, schedule, manual) |
| Job | A set of steps that run on a single runner |
| Step | An individual task — either a shell command or an action |
| Action | A reusable unit of code (from Marketplace or custom) |
| Runner | The machine (VM) that executes a job |
graph TD
W["Workflow (.github/workflows/ci.yml)"] --> EV["Event: push to main"]
W --> JB["Job: build"]
W --> JD["Job: deploy"]
JB --> B1["Step 1: Checkout code"]
JB --> B2["Step 2: Install dependencies"]
JB --> B3["Step 3: Run tests"]
JB --> B4["Step 4: Build"]
JD --> D1["Step 1: Checkout code"]
JD --> D2["Step 2: Deploy to production"]
Create a file at .github/workflows/ci.yml:
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Type check
run: npm run typecheck
- name: Run tests
run: npm test -- --coverage
- name: Build
run: npm run build
| Event | Example | Use Case |
|---|---|---|
| push | on: push | Run on every push |
| pull_request | on: pull_request | Run on PR events |
| schedule | on: schedule: cron: '0 2 * * *' | Nightly builds |
| workflow_dispatch | on: workflow_dispatch | Manual trigger |
| release | on: release: types: [published] | Publish on release |
| repository_dispatch | on: repository_dispatch | External webhook trigger |
on:
push:
branches: [main, develop]
paths:
- 'src/**'
- 'package.json'
paths-ignore:
- 'docs/**'
- '*.md'
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.