R

React Handbook

Clean • Professional

CI/CD Integration in React: Automated Deployments with GitHub Actions

3 minute

CI/CD Integration – Automated Deployments with GitHub Actions

Modern web development is not just about writing code — it’s about automating everything from testing to deployment. In React projects, CI/CD (Continuous Integration and Continuous Deployment) helps ensure that every code change is tested, built, and deployed automatically — saving time, reducing errors, and improving team efficiency.

What is CI/CD?

CI/CD stands for:

  • Continuous Integration (CI) → Automatically test and build your code whenever changes are pushed to the repository.
  • Continuous Deployment (CD) → Automatically deploy your app after the build and tests pass successfully.

Together, they create a pipeline that delivers your app to users faster and more reliably.

Why Use CI/CD in React Projects?

Using CI/CD for your React apps brings several key advantages:

  • No manual deployment – Your app is automatically deployed when you push code.
  • Fewer bugs – Automated testing ensures quality before release.
  • Consistent builds – The same environment builds every time.
  • Faster feedback – You know immediately if something breaks.
  • Collaboration ready – Perfect for teams using GitHub.

Setting Up CI/CD with GitHub Actions for React

GitHub Actions lets you automate workflows directly inside your GitHub repository. It uses YAML configuration files stored in .github/workflows/.

Let’s create one for a React project.

learn code with durgesh images

Step 1: Build Your React App

Before setting up CI/CD, ensure your app builds correctly:

npm run build

Step 2: Create a GitHub Workflow

Inside your project, create this file:

.github/workflows/deploy.yml

Step 3: Add the Workflow Configuration

Here’s an example GitHub Actions workflow for deploying a React app to GitHub Pages automatically:

name: Deploy React App

on:
  push:
    branches:
      - main  # Deploy when changes are pushed to 'main' branch

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

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

      - name: Install dependencies
        run: npm install

      - name: Build React app
        run: npm run build

      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v4
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./build

Step 4: Commit and Push Changes

Once you’ve added the workflow file, push it to your GitHub repo:

git add .
git commit -m "Add GitHub Actions deployment workflow"
git push origin main

Now, GitHub Actions will automatically:

  1. Install dependencies
  2. Build your React app
  3. Deploy the /build folder to GitHub Pages

Step 5: Check the Workflow Status

Go to your GitHub repo → Actions tab

You’ll see the CI/CD workflow running live — showing each build, test, and deployment step in real time.

CI/CD for Netlify or Vercel

If you’re deploying on Netlify or Vercel, CI/CD is even simpler:

  • Netlify: Connect your GitHub repository → every push automatically triggers a new build.
  • Vercel: Automatically detects your framework (React/Next.js) and redeploys after every commit.

No YAML setup needed — it’s all handled by the platform.

Using Environment Variables in GitHub Actions

You can add sensitive data like API keys securely in your repository:

  1. Go to GitHub → Settings → Secrets and Variables → Actions
  2. Add a new secret, e.g. REACT_APP_API_KEY
  3. Access it in your workflow:
env:
  REACT_APP_API_KEY: ${{ secrets.REACT_APP_API_KEY }}

Adding Tests to Your CI/CD Pipeline

To make your pipeline more robust, you can add automated tests before deployment:

- name: Run tests
  run: npm test -- --watchAll=false

If the tests fail, the deployment will stop automatically — ensuring code quality.

Benefits of GitHub Actions for React Deployment

FeatureBenefit
Automated DeploymentDeploys instantly after every push
Testing IntegrationRuns tests automatically
Reusable WorkflowsShare and scale CI/CD setups
Secure SecretsKeeps API keys safe
Cross-PlatformWorks with GitHub Pages, Netlify, Vercel, AWS, etc.


Article 0 of 0