Basic CI/CD for React Apps
name: CI
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm test
- run: npm run build
What CI/CD Automates
Continuous Integration automatically runs your test suite, linter, and build process every time code is pushed, catching problems immediately instead of relying on someone remembering to check manually.
Continuous Deployment takes this further, automatically deploying code that passes all checks straight to production.
A Typical React App Pipeline
A common pipeline for a React app runs, in order: install dependencies, run the linter (catching style/quality issues), run the test suite (catching functional regressions), then build the production bundle — only proceeding to deployment if every step succeeds.
Example: A GitHub Actions CI Pipeline
$ cat .github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run lint
- run: npm test
- run: npm run build
⚠️ Run this in your own terminal or Node.js environment.
Adding Automatic Deployment
Extending a CI pipeline with a deployment step (often triggered only on the main branch, after all checks pass) implements Continuous Deployment — merging to main automatically results in a live, updated production site, without a manual deploy step.
Example: Adding a Deploy Step to CI
$ cat .github/workflows/ci.yml
- run: npm run build
- name: Deploy to Netlify
if: github.ref == 'refs/heads/main'
run: npx netlify-cli deploy --prod --dir=dist
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
⚠️ Run this in your own terminal or Node.js environment.
- Not running the same checks (tests, linting) locally before pushing, discovering failures only after a slow CI run.
- Skipping tests in the CI pipeline 'to save time', defeating the whole safety-net purpose of having them there.
- Not caching dependencies (like node_modules) between CI runs, making every single run unnecessarily slow.
- Continuous Integration (CI) automatically runs checks (tests, linting, builds) on every code change.
- Continuous Deployment (CD) automatically deploys code that passes those checks to production.
- GitHub Actions is a common way to define CI/CD workflows directly alongside a repository.
- A typical pipeline: install dependencies, run linter, run tests, build, then deploy if all steps succeed.
No React-version restriction — a development/deployment workflow, not a runtime feature.
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first:
- Why Performance Matters
- Optimizing with React.memo
- Avoiding Unnecessary Re-renders
- Using the React Profiler
- Analyzing Bundle Size
- Image Optimization Techniques
- React as a PWA
- Creating a Production Build
- Environment Variables in React
- Deploying to Netlify
- Deploying to Vercel
- Basic CI/CD for React Apps
- SEO Basics for React SPAs