IntermediateLesson 6 of 9

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

Open PR
→
Actions Trigger
→
Install + Test
→
Status Check
→
Merge Allowed

Hands-on: First Workflow

yaml
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
bash
# 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

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

What is GitHub Actions?▾

GitHub’s automation platform for CI/CD workflows triggered by repository events.

Where are workflow files stored?▾

In .github/workflows/ as YAML files.

What is a job?▾

A set of steps executed on a runner.

What triggers a workflow?▾

Repository events like push, pull_request, workflow_dispatch, schedule.

Why add CI to PR flow?▾

To catch quality issues before merge and enforce release safety.

Intermediate

actions/checkout role?▾

Fetches repository code into runner workspace for subsequent steps.

Why pin action versions?▾

Stability and supply-chain safety; avoids unexpected breaking updates.

Difference between push and pull_request triggers?▾

Push runs on commits to branch; pull_request runs on PR lifecycle events against target branches.

How enforce checks before merge?▾

Enable branch protection requiring specific status checks to pass.

How optimize workflow runtime?▾

Use dependency caching, matrix scoping, and avoid unnecessary steps.

Scenario-based

PR shows “Expected — Waiting for status to be reported.”▾

Required check name may not match workflow job name; align branch protection rule with actual job identifier.

Action passes on main but fails on PR.▾

Likely PR-specific context/permissions or missing secrets for forked PR events.

Team wants manual deploy button only.▾

Use workflow_dispatch trigger and environment approvals.

Workflow consumes too many minutes.▾

Add caching, skip unchanged paths, and split expensive jobs behind conditions.

Need different test matrix per branch type.▾

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.