React Apps के लिए Basic CI/CD
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
CI/CD क्या Automate करता है
Continuous Integration हर बार code push होने पर अपने आप आपकी test suite, linter, और build process चलाता है, problems को तुरंत पकड़ते हुए बजाय किसी के manually check करना याद रखने पर निर्भर रहने के।
Continuous Deployment इसे और आगे ले जाता है, सभी checks pass करने वाले code को सीधे production में अपने आप deploy करते हुए।
एक Typical React App Pipeline
एक React app के लिए एक common pipeline order में चलता है: dependencies install करना, linter चलाना (style/quality issues पकड़ते हुए), test suite चलाना (functional regressions पकड़ते हुए), फिर production bundle build करना — deployment तक सिर्फ तब बढ़ते हुए जब हर step succeed हो।
उदाहरण: 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.
Automatic Deployment जोड़ना
एक CI pipeline को एक deployment step के साथ extend करना (अक्सर सिर्फ main branch पर trigger होता है, सभी checks pass होने के बाद) Continuous Deployment implement करता है — main में merge करना अपने आप एक live, updated production site में result करता है, बिना किसी manual deploy step के।
उदाहरण: 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.
- Push करने से पहले locally वही checks (tests, linting) न चलाना, failures को सिर्फ एक slow CI run के बाद discover करना।
- 'समय बचाने' के लिए CI pipeline में tests skip करना, उनके होने का पूरा safety-net purpose defeat करते हुए।
- CI runs के बीच dependencies (जैसे
node_modules) cache न करना, हर single run को unnecessarily धीमा बनाते हुए।
- Continuous Integration (CI) हर code change पर अपने आप checks (tests, linting, builds) चलाता है।
- Continuous Deployment (CD) उन checks को pass करने वाले code को अपने आप production में deploy करता है।
- GitHub Actions CI/CD workflows को सीधे एक repository के साथ define करने का एक common तरीका है।
- एक typical pipeline: dependencies install करना, linter चलाना, tests चलाना, build करना, फिर सभी steps pass होने पर deploy करना।
कोई React-version restriction नहीं — एक development/deployment workflow है, कोई 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