Advanced Jenkins

Backup and Configuration Management

Github Actions Basics

GitHub Actions is GitHub’s native automation platform that streamlines your CI/CD pipelines and repository workflows. Integrated directly into your GitHub repositories, it allows teams to build, test, and deploy code without leaving the GitHub environment.

What Is GitHub Actions?

GitHub Actions lets you define custom workflows in YAML files, which execute on specified events—such as pushes, pull requests, and releases—to automate tasks like building, testing, and deployment.

The image shows a GitHub Actions interface displaying a list of workflow runs for a project, with details such as commit messages, status, and branch information.

With GitHub Actions, you can:

  • Automate CI/CD pipelines for every pull request.
  • Deploy merged changes to staging or production.
  • Integrate with hundreds of third-party services via community actions.

The image shows a GitHub Actions interface with a workflow in progress for a project. It includes details about a recent push, the status of the workflow, and a visual representation of the job steps.

How GitHub Manages Infrastructure

GitHub Actions abstracts away the underlying servers and environments, so you don’t have to:

  1. Provision virtual machines
  2. Scale resources automatically
  3. Configure execution environments

The image is an infographic titled "GitHub Manages Infrastructure," showing three steps: setting up servers, scaling resources, and managing the execution environment.

When a workflow runs, GitHub:

  • Spins up a fresh VM or container.
  • Caches dependencies for faster builds.
  • Executes your steps in sequence.
  • Provides detailed logs and artifacts.

Triggers and Automation Use Cases

GitHub Actions supports a wide range of events beyond CI/CD. You can automate:

Trigger TypeUse CaseExample
pushRun tests on every commitBuild and test a library
pull_requestValidate contributionsLint code, run unit tests, and post status checks
issuesManage issue workflowsAutomatically label or assign new issues
releasePublish packagesBuild Docker image and push to Docker Hub
registry_packageRespond to package registry eventsNotify team of new package version

The image illustrates GitHub Actions for automating CI/CD processes, including building, unit testing, linting, dockerizing, security, deployment, and tests.

The image is a flowchart illustrating GitHub Actions for automating repository actions, including pull requests, issues, releases, and registry packages, with various states like open, closed, and published.

Creating Your First Workflow

Workflows are defined in YAML files inside the .github/workflows directory of your repository.

Note

Each workflow file must be valid YAML and include at least one trigger (on), one job, and one step.

Below is a sample workflow that runs unit tests on Ubuntu, macOS, and Windows runners:

name: CI Test Pipeline
on: [push, pull_request]

jobs:
  unit-test:
    name: Run Unit Tests
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}

    steps:
      - name: Checkout Repository
        uses: actions/checkout@v3

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'

      - name: Install Dependencies
        run: npm ci

      - name: Execute Tests
        run: npm test

Key points:

  • on: Defines events that trigger the workflow.
  • strategy.matrix: Runs jobs in parallel across multiple operating systems.
  • runs-on: Specifies the runner environment.
  • steps: Each step is a shell command or an action.

During execution, view real-time logs and download artifacts from the Actions tab of your repository.

The image illustrates a GitHub Actions workflow, showing a project with unit testing jobs for different operating systems (Ubuntu, macOS, Windows) and the steps involved in each job using GitHub hosted runners.

Runner Types Comparison

Choose between GitHub-hosted and self-hosted runners based on your requirements:

FeatureGitHub-Hosted RunnersSelf-Hosted Runners
ProvisioningAutomaticManual
CustomizationLimited to OS selectionFull control over software and hardware
ScalingHandled by GitHubManaged by your team
CostIncluded with GitHub plan (usage limits apply)Infrastructure maintenance
Preinstalled ToolsCommon languages and toolsUser-defined

The image compares GitHub-hosted and self-hosted runners, highlighting their features and differences in terms of hosting, customization, control, and costs.

Warning

Self-hosted runners can pose security risks if not properly isolated. Ensure that you follow your organization’s security policies.

Next Steps & References

In this guide, we covered:

  • Core concepts: workflows, jobs, steps, and runners
  • Workflow file structure and sample CI pipeline
  • Event triggers and practical use cases

For deeper dives:

Stay tuned for advanced patterns, custom action development, and workflow optimization in upcoming lessons!

Watch Video

Watch video content

Previous
Migrating Jenkins to Another Node