Endurative

Mastering CI/CD with GitHub Actions: A Beginner's Guide (2025)

CI/CD stands for Continuous Integration and Continuous Deployment. These are software development practices that help teams automate the process of building, testing, and deploying their code. GitHub Actions is a powerful tool built into GitHub that allows you to automate these CI/CD workflows directly within your repository.

  1. Continuous Integration (CI): This is the practice of automatically building and testing code every time a change is pushed to a shared repository. CI helps catch bugs early by automatically running tests, linting, and building your code.
  2. Continuous Deployment (CD): This takes CI a step further. After your code passes all automated tests, it is automatically deployed to a production environment without any manual intervention. This could mean publishing your web app to a service like Vercel, AWS, or Netlify.

GitHub Actions uses a workflow file written in YAML to define your CI/CD process. This file lives in the .github/workflows/deploy.yml directory of your repository.

Example: A Basic CI/CD Workflow for Deployment

Here is a simplified and improved version of the YAML file for a Vercel deployment. This example is more readable and includes helpful comments.

# A CI/CD workflow to deploy a web application to Vercel.
name: Deploy to Vercel

# Triggers the workflow on every push to the 'main' branch.
on:
push:
branches:
- main
# Defines a single job named 'deploy'.
jobs:
deploy:
# Specifies the virtual machine environment for the job.
runs-on: ubuntu-latest
# The steps that make up the 'deploy' job.
steps:
# Step 1: Checks out the latest code from the repository.
- name: Checkout Code
uses: actions/checkout@v4
# Step 2: Installs project dependencies.
- name: Install Dependencies
run: npm install
# Step 3: Builds the project for production.
- name: Build Project
run: npm run build
# Step 4: Deploys the built project to Vercel.
- name: Deploy to Vercel
run: npx vercel --prod --token=${{ secrets.VERCEL_TOKEN }}

By leveraging GitHub Actions, you can automate your CI/CD pipeline, ensuring your code is consistently tested and deployed. This process not only saves time but also improves code quality and team collaboration.