GitHub Actions (Basic Intro)
Set up your first CI workflow that runs automatically on pull requests and verifies code quality before merge.
Simple Explanation (ELI5)
GitHub Actions is a robot teammate. When someone opens a PR, it automatically runs your checklist: install dependencies, run tests, and tell you pass/fail.
Technical Explanation
A workflow is YAML under .github/workflows/. It has triggers (on), jobs, and steps. Jobs run on runners (virtual machines). CI status integrates with branch protection so only passing PRs can merge.
Visual: Basic CI Flow
Hands-on: First Workflow
name: ci-basic
on:
pull_request:
branches: ["main"]
push:
branches: ["main"]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install
run: npm ci
- name: Lint
run: npm run lint --if-present
- name: Test
run: npm test -- --ci# Create workflow directory mkdir -p .github/workflows # Save YAML as .github/workflows/ci-basic.yml # Commit and push git add .github/workflows/ci-basic.yml git commit -m "ci: add basic GitHub Actions workflow" git push origin feature/ci-basic
Debugging Scenarios
- Workflow not running: Confirm trigger branch names match exactly.
- npm ci fails: Lockfile mismatch or missing package lock.
- Action version errors: Pin supported action tags (
@v4, not floating@main). - Permission denied: Check default
GITHUB_TOKENpermissions in repo settings.
Real-world Use Case
After introducing required CI checks on PRs, a product team prevented untested hotfixes from entering main. Defect escape rate dropped because failing tests blocked merges automatically.
Interview Questions
Beginner
GitHub’s automation platform for CI/CD workflows triggered by repository events.
In .github/workflows/ as YAML files.
A set of steps executed on a runner.
Repository events like push, pull_request, workflow_dispatch, schedule.
To catch quality issues before merge and enforce release safety.
Intermediate
Fetches repository code into runner workspace for subsequent steps.
Stability and supply-chain safety; avoids unexpected breaking updates.
Push runs on commits to branch; pull_request runs on PR lifecycle events against target branches.
Enable branch protection requiring specific status checks to pass.
Use dependency caching, matrix scoping, and avoid unnecessary steps.
Scenario-based
Required check name may not match workflow job name; align branch protection rule with actual job identifier.
Likely PR-specific context/permissions or missing secrets for forked PR events.
Use workflow_dispatch trigger and environment approvals.
Add caching, skip unchanged paths, and split expensive jobs behind conditions.
Use conditional expressions and matrix includes based on github.ref.
Summary
GitHub Actions provides immediate CI value with minimal setup. A simple PR-triggered workflow can dramatically increase merge confidence and team consistency.