TechyPilots Info
TechyPilots.INFO
Home/Tutorials/CI/CD/GitHub Actions
CI/CD Automation Tutorial

GitHub Actions

Learn how to automate builds, testing, deployments, and software workflows using GitHub Actions and YAML-based CI/CD pipelines.

Level: Beginner to Intermediate
Topic: CI/CD Automation

GitHub Actions Workflow

Automate Your Software Workflow

GitHub Event

Workflow Trigger

Runner

Build & Test

Deploy Application

Introduction

What is GitHub Actions?

GitHub Actions is an automation platform that can be used to build, test, and deploy software directly from a GitHub repository.

Workflows are defined using YAML files and can run automatically when repository events occur, manually when requested, or on a schedule.

A workflow contains jobs, and jobs contain steps that execute commands or reusable actions on a runner.

Core Concepts

Understanding GitHub Actions

GitHub Actions workflows combine events, jobs, runners, steps, and reusable actions to automate development and deployment processes.

01

Workflows

A workflow is an automated process defined in a YAML file. A workflow can contain one or more jobs and can run when configured events occur.

Key Topics

  • YAML files
  • Automation
  • Workflow triggers
  • Repository workflows
02

Events

Events trigger workflow runs. Common examples include pushing code, opening a pull request, manually running a workflow, or running on a schedule.

Key Topics

  • Push
  • Pull request
  • Manual trigger
  • Scheduled workflow
03

Jobs

A job is a collection of steps that runs on a runner. Jobs can run independently, in parallel, or depend on other jobs.

Key Topics

  • Job dependencies
  • Parallel jobs
  • Sequential jobs
  • Runner execution
04

Steps

Steps are individual tasks inside a job. A step can run shell commands or use reusable actions.

Key Topics

  • Shell commands
  • Reusable actions
  • Build tasks
  • Test tasks

Workflow Architecture

Main components of GitHub Actions

Workflow File

A YAML configuration file stored inside the .github/workflows directory of a repository.

Trigger

Defines the events or conditions that start a workflow run.

Job

A group of steps executed on the same runner environment.

Runner

The machine or environment that executes a workflow job.

Step

An individual task that runs a command or uses an action.

Action

A reusable unit that performs a specific task within a workflow.

Getting Started

Where are workflow files stored?

GitHub Actions workflow files are typically stored inside the.github/workflowsdirectory of your repository.

Each workflow is defined using a YAML file with a.ymlor.yamlextension.

Example Repository Structure

my-project/
│
├── src/
│
├── package.json
│
└── .github/
    └── workflows/
        └── ci.yml

Your First Workflow

Create a basic CI workflow

This example demonstrates a basic workflow that runs when code is pushed to the main branch or when a pull request targets the main branch.

The workflow checks out the repository, configures Node.js, installs dependencies, runs tests, and builds the application.

`.github/workflows/ci.yml`

name: Node.js CI

on:
  push:
    branches:
      - main

  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "20"

      - name: Install dependencies
        run: npm ci

      - name: Run tests
        run: npm test

      - name: Build application
        run: npm run build

Workflow Execution

How a GitHub Actions workflow runs

01

Event Occurs

A configured repository event occurs, such as a push or pull request.

02

Workflow Starts

GitHub identifies the matching workflow and starts a workflow run.

03

Jobs Run

The workflow jobs execute on configured runners.

04

Steps Execute

Each job performs its configured commands and actions.

05

Results Are Reported

GitHub displays the status and output of the workflow execution.

06

Next Stage

Successful workflows can continue to deployment or other automated processes.

Use Cases

What can you automate?

GitHub Actions can automate many tasks across the software development lifecycle and repository workflows.

Continuous Integration

Automatically build and test application changes whenever developers push code or open pull requests.

Continuous Deployment

Automate the process of deploying validated application changes to development, staging, or production environments.

Code Quality Checks

Run linting, formatting, security checks, and other validation processes automatically.

Container Builds

Build and publish Docker container images as part of an automated workflow.

Scheduled Automation

Run workflows at scheduled times for maintenance, reports, backups, or other recurring tasks.

Repository Automation

Automate repository tasks such as issue labeling, notifications, pull request workflows, and other processes.

Learning Roadmap

How to learn GitHub Actions

Follow these steps to build your first workflows and progress toward complete CI/CD automation.

Step 1

Create a GitHub Repository

Start with a repository containing an application or project that you want to automate.

Step 2

Create a Workflow File

Create a YAML workflow inside the .github/workflows directory.

Step 3

Configure a Trigger

Choose when the workflow should run, such as when code is pushed or a pull request is opened.

Step 4

Add Jobs and Steps

Define the tasks required to build, test, package, or deploy your application.

Step 5

Run and Monitor

Push code or manually trigger the workflow and inspect the execution results.

Step 6

Build a Complete Pipeline

Combine building, testing, packaging, and deployment into a complete CI/CD workflow.

Best Practices

GitHub Actions best practices

Keep Workflows Focused

Create workflows with clear responsibilities instead of placing every automation task into one large workflow.

Use Versioned Actions

Specify action versions or immutable references to improve workflow stability and control.

Store Secrets Securely

Use repository or environment secrets for sensitive credentials instead of placing them directly in workflow files.

Use Clear Job Names

Use descriptive workflow, job, and step names so pipeline execution is easier to understand.

Test Pipeline Changes

Validate workflow modifications before relying on them for important deployment processes.

Monitor Workflow Results

Review workflow logs and failures to identify automation and application issues quickly.

Next Step

Start building GitHub Actions workflows

Practice creating workflows, configuring triggers, running jobs, using actions, testing applications, and building automated CI/CD pipelines.