Featured image of post Getting Started with CI/CD Using GitHub ActionsFeatured image of post Getting Started with CI/CD Using GitHub Actions

Getting Started with CI/CD Using GitHub Actions

A beginner-friendly guide to CI/CD with GitHub Actions, covering the essentials for your first automation setup.

If “CI/CD” sounds like something you should know but don’t know where to start, this guide is for you. GitHub Actions makes continuous integration and delivery accessible to everyone with a GitHub repository.

What is GitHub Actions?

GitHub Actions is a CI/CD platform built directly into GitHub. It lets you automate testing, building, and deploying right from your repository. Workflows trigger on pushes, pull requests, or scheduled events.

1. Workflow Basics

Place a YAML file inside .github/workflows/ to define your workflow.

.github/
└── workflows/
    └── ci.yml

Here’s the basic structure:

name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - run: npm test

Key Elements

ElementDescription
nameWorkflow name shown on GitHub
onTrigger events (push, pull_request, schedule, etc.)
jobsCollection of jobs that can run in parallel
runs-onRunner environment (ubuntu-latest, windows-latest, macos-latest)
stepsIndividual tasks within a job
usesReuse an existing action
runExecute a shell command directly

2. Trigger Variations

# On push
on: push

# On pull request
on: pull_request

# Scheduled (cron)
on:
  schedule:
    - cron: '0 9 * * 1'  # Every Monday at 9:00 UTC

# Manual trigger
on:
  workflow_dispatch:

3. Using Marketplace Actions

Thousands of actions are available on GitHub Marketplace. Here are the most common ones:

- uses: actions/checkout@v4          # Checkout repository
- uses: actions/setup-node@v4        # Setup Node.js
- uses: actions/setup-python@v5      # Setup Python
- uses: docker/login-action@v3       # Login to Docker registry
- uses: actions/cache@v4             # Cache dependencies
- uses: actions/upload-artifact@v4   # Upload build artifacts

4. Matrix Builds for Parallel Testing

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18, 20, 22]
        os: [ubuntu-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm ci
      - run: npm test

That’s six combinations running automatically.

5. Secrets and Environment Variables

Store API keys and passwords in Settings → Secrets and variables → Actions on GitHub.

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: deploy.sh
        env:
          API_KEY: ${{ secrets.API_KEY }}
          DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}

Never write secrets directly into your YAML files.

6. Caching Dependencies

Caching node_modules or ~/.npm can significantly speed up your workflows.

- name: Cache Node Modules
  uses: actions/cache@v4
  with:
    path: ~/.npm
    key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
    restore-keys: |
      ${{ runner.os }}-node-

7. Deployment Example (GitHub Pages)

name: Deploy to GitHub Pages

on:
  push:
    branches: [main]

permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - run: npm run build
      - uses: actions/configure-pages@v4
      - uses: actions/upload-pages-artifact@v3
        with:
          path: ./out
      - uses: actions/deploy-pages@v4

Summary

GitHub Actions is one of the easiest CI/CD tools to get started with — just drop a YAML file into .github/workflows/. Start with a simple “run tests on push” workflow, then gradually explore matrix builds, caching, and automated deployments.