CI/CD Pipelines with GitHub Actions

May 25, 2025
|
11 min

Continuous Integration and Continuous Deployment (CI/CD) are now critical components of modern software development. They allow teams to build, test, and release code faster and more reliably. One of the most developer-friendly tools to implement CI/CD is GitHub Actions—a native feature within GitHub that allows you to automate workflows directly in your repository.

In this article, we’ll break down what CI/CD means, how GitHub Actions works, and how you can set up your first CI/CD pipeline in minutes.

🔁 What is CI/CD?

Continuous Integration (CI) is the practice of automatically integrating code changes from multiple contributors into a shared repository several times a day. Every change is validated by automated tests to detect problems early.

Continuous Deployment (CD) takes CI a step further by automatically deploying every validated change to a production environment. Together, CI/CD drastically reduce integration problems and accelerate development velocity.

⚙️ Why GitHub Actions?

GitHub Actions is a powerful automation tool built right into GitHub. Here’s why it’s a solid choice:

Native GitHub Integration: No need to leave GitHub to manage workflows.

  1. Custom Workflows: Automate tasks like testing, linting, packaging, and deployment.

  2. Marketplace: Thousands of pre-built actions for common tools and services.

  3. Matrix Builds: Test across multiple versions and OSs.

  4. Self-hosted Runners: Option to run workflows on your own infrastructure.

🧪 A Basic CI Pipeline with GitHub Actions

Let’s start with a simple Node.js example to run tests on every push or pull request.

name: CI Pipeline
 
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
 
jobs:
  test:
    runs-on: ubuntu-latest
 
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
 
      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'
 
      - name: Install dependencies
        run: npm ci
 
      - name: Run tests
        run: npm test

This basic workflow:

  1. Triggers on pushes and PRs to the main branch

  2. Installs Node.js

  3. Runs npm ci to install dependencies

  4. Executes the test suite with npm test

🚀 Adding CD to the Pipeline

To complete your CI/CD setup, let’s add deployment. Assume we’re deploying a static site to GitHub Pages:

jobs:
  # ... existing CI job
 
  deploy:
    needs: test
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'
 
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
 
      - name: Build static site
        run: npm run build
 
      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./dist

This job:

  1. Waits for tests to pass

  2. Builds the project

  3. Deploys the contents of ./dist to GitHub Pages

🧠 Best Practices for GitHub Actions

  1. Use Secrets for Credentials: Store API keys and tokens in GitHub Secrets.

  2. Keep Workflows Modular: Split large workflows into smaller, reusable ones.

  3. Cache Dependencies: Use actions/cache to speed up workflow execution.

  4. Run Linting: Catch issues early with linting and formatting steps.

  5. Pin Action Versions: Avoid unexpected breakage by pinning action versions.

Conclusions

GitHub Actions lowers the barrier to setting up reliable CI/CD pipelines. It’s tightly integrated with your development workflow, easy to configure, and flexible enough to handle complex deployments.

Whether you're maintaining a simple static site or deploying a full-stack app, GitHub Actions offers a scalable path to automation. Start small, iterate fast, and let automation power your delivery pipeline.