docs
GitHub CI/CD Deployment
Intro

Introduction to GitHub CI/CD 🚀

Continuous Integration (CI) and Continuous Deployment (CD) are essential practices in modern software development, ensuring that code is built, tested, and deployed automatically whenever changes are made. GitHub offers powerful CI/CD capabilities through GitHub Actions, making it easier to automate your development workflow directly in your repository.

What is CI/CD? 🤔

  • Continuous Integration (CI): Automatically build and test code whenever a developer pushes changes to the repository. This ensures that the codebase remains stable and helps catch bugs early in the development process.

  • Continuous Deployment (CD): Automatically deploy code to production or staging environments once it passes all required tests and checks, ensuring faster and more reliable releases.

Why Use GitHub CI/CD? 💡

  • Integrated with GitHub: GitHub Actions is fully integrated with your GitHub repository, allowing you to automate workflows directly from your codebase without third-party tools.
  • Automation: Automatically build, test, and deploy your code on every push or pull request.
  • Custom Workflows: Create custom workflows using YAML files to define steps for testing, building, and deploying your application.
  • Cost Efficiency: GitHub Actions offers a free tier with generous usage limits, making it a cost-effective option for teams of all sizes.

Key Components of GitHub Actions 🔑

  • Workflows: The core element of GitHub Actions, defined in .yml files located in the .github/workflows/ directory. Workflows describe the automation process, including when to trigger it (e.g., on push, pull request) and the jobs it will perform.

  • Jobs: Each workflow is made up of one or more jobs, which run in parallel or sequentially. A job might consist of steps like building the code, running tests, or deploying to production.

  • Actions: Individual tasks that are executed as part of a job. GitHub provides a marketplace of predefined actions (e.g., checking out code, setting up a Node.js environment), or you can create custom actions.

Basic CI/CD Workflow Example 📝

Here’s a basic example of a GitHub Actions workflow that builds and tests a Node.js application:

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