← Back to tools

CI/CD

GitHub Actions Documentation

GitHub Actions automates CI/CD directly in GitHub repositories.

Level: Intermediate

What Is GitHub Actions?

GitHub Actions is a intermediate-level DevOps tool used to manage specific parts of software delivery and operations. It helps teams standardize workflows and reduce manual effort.

Why We Use It

Teams use GitHub Actions to improve speed, reliability, and consistency. It reduces repetitive manual work, lowers failure risk, and makes collaboration easier across development and operations.

Where It Fits In DevOps

It is the automation core of software delivery, moving code from commit to tested and deployable artifacts.

From Beginner To End-to-End

1. Foundations

Start with core GitHub Actions concepts and basic setup so you can use it safely in day-to-day work.

- Understand GitHub Actions fundamentals

- Set up local/dev environment

- Run first working example

2. Team Workflow

Integrate GitHub Actions into real team practices with repeatable conventions and collaboration patterns.

- Adopt standards and naming conventions

- Integrate with repositories and CI/CD

- Create reusable templates

3. Production Operations

Use GitHub Actions in production with observability, security, and rollback plans.

- Monitor behavior and failures

- Secure access and secrets

- Define incident and rollback flow

4. Scale and Optimization

Continuously improve reliability, performance, and cost while standardizing usage across services.

- Improve performance and cost

- Automate compliance checks

- Document best practices for the team

Key Concepts

- Workflows

- Jobs

- Runners

Learning Path

- Build CI workflow

- Add tests

- Add deployment gates

Real Use Cases

- Automated test pipelines

- Release and deployment workflows

- Quality gates and change approvals

Beginner Learning Plan

- Read the GitHub Actions basics and terminology

- Run at least one hands-on mini project

- Break and fix a small setup to build confidence

- Document your first repeatable workflow

Advanced / Production Plan

- Integrate GitHub Actions with your full delivery pipeline

- Add security and policy checks

- Add observability and incident playbooks

- Define reusable standards for multiple services

Common Mistakes

- Using defaults in production without security hardening

- Skipping monitoring and post-deployment validation

- No rollback strategy for failed changes

- Over-complex setup before mastering fundamentals

Production Readiness Checklist

- Access control and least privilege applied

- Secrets managed securely

- Monitoring and alerting enabled

- Rollback and recovery process tested

- Documentation updated for team onboarding

Installation Guide

Install GitHub Actions on host with practical commands and verification steps.

Install GitHub CLI

sudo apt update && sudo apt install -y gh

Authenticate

gh auth login

Initialize workflow folder

mkdir -p .github/workflows
touch .github/workflows/ci.yml

Quick Start

Create workflow folder

mkdir -p .github/workflows

Add CI file

touch .github/workflows/ci.yml

Push to trigger

git push origin main

Common Commands

Simple command list with short descriptions.

gh workflow list

List workflows in the repository.

gh run list

List recent workflow runs.

gh run view <id>

Open details for a workflow run.

gh run watch <id>

Watch run progress in terminal.

gh run rerun <id>

Rerun a failed workflow run.

gh secret set MY_SECRET

Set a repository secret from terminal.

gh variable set MY_VAR

Set a repository variable.

act

Run GitHub Actions locally (if installed).

Reference

Official documentation:

https://docs.github.com/actions

Complete Guide

A full, structured guide for this tool (with commands, diagrams, best practices, and learning path).

GitHub Actions

A complete DevOpsLabX guide for GitHub Actions: what it is, why we use it, key concepts, commands, best practices, and how to learn it.

At A Glance

  • Category: CI/CD
  • Difficulty: Intermediate
  • Outcome: learn the fundamentals, then build real workflows, then make it production-ready

Prerequisites

  • Git basics (commit/branch/pull request)
  • Basic build/test understanding for your language (Node, Java, Python, etc.)
  • Basic Linux and CLI navigation

Glossary

  • Workflow: A YAML file that defines automation.
  • Job: A unit of work running on a runner.
  • Step: An action or shell command inside a job.
  • Runner: The machine that executes jobs (hosted or self-hosted).
  • Artifact: A saved output of the workflow (build output, logs, etc.).

Overview

GitHub Actions automates CI/CD directly in GitHub repositories.

Architecture Diagram

A real, visual mental model of how GitHub Actions fits into a typical workflow.

GitHub Actions Workflow

Commitpush / PRCIbuild + testArtifactimage/packageStagingdeployValidationchecksProductionrelease

This diagram is a practical mental model, not vendor-specific.

Reference Architecture (Production)

A production-oriented view: guardrails, checks, and the parts that matter when it breaks.

Production Reference Flow

Commitpush / PRCIbuild + testArtifactimage/packageStagingdeployValidationchecksProductionrelease

This diagram is a practical mental model, not vendor-specific.

Key Concepts

  • Workflows
  • Jobs
  • Runners

Concept Deep Dive

Workflows

Workflows is a core idea you’ll use repeatedly while working with GitHub Actions.

Why it matters: Understanding Workflows helps you design safer workflows and troubleshoot issues faster.

Practice:

  • Explain Workflows in your own words (1 minute rule).
  • Find where Workflows appears in real docs/configs for GitHub Actions.
  • Create a small example that uses Workflows, then break it and fix it.

Jobs

Jobs is a core idea you’ll use repeatedly while working with GitHub Actions.

Why it matters: Understanding Jobs helps you design safer workflows and troubleshoot issues faster.

Practice:

  • Explain Jobs in your own words (1 minute rule).
  • Find where Jobs appears in real docs/configs for GitHub Actions.
  • Create a small example that uses Jobs, then break it and fix it.

Runners

Runners is a core idea you’ll use repeatedly while working with GitHub Actions.

Why it matters: Understanding Runners helps you design safer workflows and troubleshoot issues faster.

Practice:

  • Explain Runners in your own words (1 minute rule).
  • Find where Runners appears in real docs/configs for GitHub Actions.
  • Create a small example that uses Runners, then break it and fix it.

Core Workflow

1. Foundations

Start with core GitHub Actions concepts and basic setup so you can use it safely in day-to-day work.

Goals:

  • Understand GitHub Actions fundamentals
  • Set up local/dev environment
  • Run first working example

2. Team Workflow

Integrate GitHub Actions into real team practices with repeatable conventions and collaboration patterns.

Goals:

  • Adopt standards and naming conventions
  • Integrate with repositories and CI/CD
  • Create reusable templates

3. Production Operations

Use GitHub Actions in production with observability, security, and rollback plans.

Goals:

  • Monitor behavior and failures
  • Secure access and secrets
  • Define incident and rollback flow

4. Scale and Optimization

Continuously improve reliability, performance, and cost while standardizing usage across services.

Goals:

  • Improve performance and cost
  • Automate compliance checks
  • Document best practices for the team

Quick Start

  1. Create workflow folder
mkdir -p .github/workflows
  1. Add CI file
touch .github/workflows/ci.yml
  1. Push to trigger
git push origin main

Tutorial Series

A tutorial-style sequence (like a handbook). Do these in order to build skill from beginner to production.

Tutorial 1: First Pipeline: Build + Test

Goal: Create a minimal pipeline that runs on every push.

Steps:

  1. Verify you understand what the tool does and what problem it solves.
  2. Install or enable it on your machine (or in a sandbox environment).
  3. Run the smallest working example and write down what happened.
  4. Define a workflow with one job and a few steps (checkout, install, test).
  5. Make it fail on purpose, then fix it.

Checkpoints:

  • You can read pipeline logs and find the failing step
  • You can reproduce locally what failed in CI

Exercises:

  • Add caching for dependencies
  • Add a lint step before tests

Tutorial 2: Artifacts and Environments

Goal: Understand how to pass outputs from build to deploy safely.

Steps:

  1. Produce a build artifact (zip, image, binary) and store it as an artifact.
  2. Create staging vs production behavior using environment variables.

Checkpoints:

  • You can keep secrets out of logs
  • You can deploy the same artifact across environments

Exercises:

  • Add a manual approval step for production
  • Add a rollback command in a runbook

Tutorial 3: Release Safety

Goal: Add guardrails so deployments are safe.

Steps:

  1. Break one thing intentionally and practice debugging from logs/output.
  2. Write a short checklist: what to check first, second, third.
  3. Add a health check step after deploy (HTTP check, readiness check).
  4. Add a rollback strategy (revert, previous image tag, previous release).

Checkpoints:

  • You know your rollback plan
  • You can detect failure quickly with a single check

Exercises:

  • Simulate a failed deploy and run the rollback
  • Write a post-deploy verification checklist

Command Cheatsheet

  • gh workflow list: List workflows in the repository.
  • gh run list: List recent workflow runs.
  • gh run view <id>: Open details for a workflow run.
  • gh run watch <id>: Watch run progress in terminal.
  • gh run rerun <id>: Rerun a failed workflow run.
  • gh secret set MY_SECRET: Set a repository secret from terminal.
  • gh variable set MY_VAR: Set a repository variable.
  • act: Run GitHub Actions locally (if installed).

Learning Path

  • Build CI workflow
  • Add tests
  • Add deployment gates

Beginner To Advanced Path

Beginner Path (Foundations)

What to learn:

  • Learn GitHub Actions terminology and the “why” behind it
  • Install/setup and run a first working example
  • Understand the main components and the default workflow
  • Learn safe debugging: where to look when something fails
  • Build a small checklist for your own repeatable setup
  • Write notes (commands, errors, fixes) while learning

Hands-on labs:

  • Follow a hello-world style tutorial and document every step
  • Break one config intentionally and fix it (learn error patterns)
  • Write a 10-command cheat sheet you can reuse later
  • Create a simple diagram of the tool’s flow in your own words

Milestones:

  • You can explain the tool in 2 minutes
  • You can reproduce a working setup from scratch
  • You can troubleshoot the top 3 common failures
  • You can share a clean quick-start with someone else

Intermediate Path (Real Workflows)

What to learn:

  • Use the tool inside a realistic DevOps workflow
  • Create reusable templates/configs and standard naming conventions
  • Add security basics: secrets handling and least privilege
  • Reduce toil: automate repeated steps and build confidence
  • Make the workflow faster and safer (cache, validations, checks)
  • Document the workflow as if onboarding a new teammate

Hands-on labs:

  • Integrate it with a CI pipeline (lint/build/test/deploy style flow)
  • Parameterize config for dev/stage/prod environments
  • Create a runbook: steps to validate and roll back a change
  • Add a preflight validation step that blocks unsafe changes

Milestones:

  • You can onboard another person with your docs
  • You can run the tool consistently across environments
  • You can explain tradeoffs (speed vs safety, flexibility vs complexity)
  • You can debug failures using logs/outputs without guesswork

Advanced Path (Production & Scale)

What to learn:

  • Operate the tool safely in production with guardrails
  • Add observability: metrics/logs/traces and meaningful alerts
  • Optimize performance/cost and standardize across multiple services
  • Design failure modes and recovery (rollback, restore, incident flow)
  • Create upgrade strategy and test it (versioning, compatibility)
  • Create ownership: docs, alerts, dashboards, and operational SLAs

Hands-on labs:

  • Add policy checks (security scans, approvals, protected environments)
  • Load test or scale test the workflow and measure bottlenecks
  • Create an incident simulation and write a postmortem template
  • Automate audits: drift checks, compliance checks, and reports

Milestones:

  • You can detect failures quickly and recover safely
  • You can maintain the setup long-term (upgrade strategy, docs, ownership)
  • You can explain architecture decisions and alternatives
  • You can standardize patterns across multiple services/teams

Hands-On Labs

Beginner Labs

  • Create a GitHub Actions pipeline that runs lint + unit tests
  • Make the pipeline fail intentionally and fix it
  • Add caching to reduce runtime
  • Add artifact upload and inspect outputs

Intermediate Labs

  • Add a staging deploy job with smoke tests
  • Use environments and protected secrets
  • Add a manual approval gate for production
  • Add notifications for failures

Advanced Labs

  • Add security scanning (deps + SAST) and block merges on critical issues
  • Add canary/blue-green release strategy (if applicable)
  • Add audit trail: deployment metadata, commit sha, actor
  • Add rollback automation

Advanced Topics

  • Monorepo workflows and selective builds
  • Reusable pipeline templates and shared actions
  • Parallelization, caching, and flaky test containment
  • Progressive delivery: canary, blue/green, feature flags
  • Supply chain security (SBOM, provenance) for GitHub Actions

Production Patterns

  • Protected main branch + required checks
  • Build cache and artifact retention policy
  • Deployment environments (dev/stage/prod) with approvals
  • Rollback strategy (revert + redeploy) for GitHub Actions workflows
  • Audit logs for who deployed what and when

Real-World Scenarios

  • Build and test runs on every PR using GitHub Actions with fast feedback.
  • Create a safe deploy pipeline with staging validation and rollback strategy.
  • Add security checks: dependency scan, secret scanning, and approvals for prod.

Troubleshooting

  • Reproduce the issue with the smallest possible example
  • Check logs/output first, then configuration, then permissions/credentials
  • Validate inputs (versions, environment variables, file paths, network access)
  • Rollback to last known-good state if production is affected
  • Write down the root cause and add a guardrail so it does not repeat

Runbook Templates

Use these templates to make your docs feel like real production documentation.

Deploy Runbook

  • Purpose
  • Preconditions (secrets, access, approvals)
  • Steps to deploy (exact commands)
  • Post-deploy verification (health checks)
  • Rollback steps
  • Owner and escalation

Incident Triage Runbook

  • Impact assessment (who is impacted?)
  • Current signals (errors, latency, saturation)
  • Recent changes (deploys, config, infra)
  • First checks (logs, health endpoints, dependencies)
  • Mitigation steps (rate limiting, rollback, scale)
  • Follow-up actions (postmortem, guardrails)

Checklist (Copy/Paste)

  • What changed since it last worked?
  • What do logs say at the exact failure time?
  • Is the service reachable on the expected port and DNS?
  • Are credentials/permissions valid?
  • Is disk full, memory exhausted, or CPU pegged?
  • Do we have a safe rollback plan and is it tested?

Security & Best Practices

  • Never hardcode secrets in code or commits
  • Use least privilege (roles, scopes, minimal permissions)
  • Prefer reproducible builds/configs over manual steps
  • Add validations before applying changes (lint/validate/plan/dry-run)
  • Keep documentation and runbooks updated
  • Version pin critical dependencies and plan upgrades

Common Error Patterns

Symptom

Pipeline fails only in CI (works locally)

Likely cause: Missing env vars, different tool/runtime versions, or missing system deps on runner

Fix steps:

  • Print versions in CI and match local
  • Ensure build does not require local-only .env at compile time
  • Install system dependencies explicitly in the workflow

Symptom

Deploy succeeded but app is broken

Likely cause: No post-deploy validation and no rollback guardrails

Fix steps:

  • Add smoke tests after deploy
  • Require approval for production deploys
  • Implement rollback via revert + redeploy or previous artifact

FAQ

What is GitHub Actions used for?

GitHub Actions is used to standardize and automate parts of delivery and operations so teams can ship faster and more reliably.

How long does it take to learn GitHub Actions?

You can get productive in days with fundamentals, but production mastery comes from building workflows, debugging failures, and operating it over time.

What should I learn before GitHub Actions?

Learn basic Linux + Git first, then follow the prerequisites section. Fundamentals make every advanced topic easier.

How do I use GitHub Actions safely in production?

Add guardrails: least privilege, validation before apply/deploy, monitoring, and a tested rollback plan.

Common Mistakes

  • Using defaults in production without security hardening
  • Skipping monitoring and post-deployment validation
  • No rollback strategy for failed changes
  • Over-complex setup before mastering fundamentals

Production Readiness Checklist

  • Access control and least privilege applied
  • Secrets managed securely
  • Monitoring and alerting enabled
  • Rollback and recovery process tested
  • Documentation updated for team onboarding

Mini Projects

  • Build a small project that uses GitHub Actions in a realistic workflow
  • Write a checklist for production usage
  • Create a troubleshooting runbook for common failures
  • Create a one-page internal doc: setup, usage, debugging, rollback

Interview Questions

  • Explain what GitHub Actions is and where it fits in DevOps.
  • Describe a real problem you solved using GitHub Actions.
  • What can go wrong in production, and how do you detect and recover?
  • What is the difference between CI, continuous delivery, and continuous deployment?
  • How do you manage secrets in pipelines?
  • How do you design rollbacks and safe deployments?

References

Extended Documentation

Extra long-form notes for GitHub Actions. This loads on demand so the page stays fast.