CI/CD
What is CI/CD?
Think of CI/CD like an automatic quality checker plus a delivery robot for your code. Every push is tested, and every safe build can deploy without manual intervention.
Steps Involved in CI
- Push code to the repository.
- Install dependencies in a clean environment.
- Run linting and automated tests.
- Publish test reports and fail fast on errors.
Steps Involved in CD
- Build a production-ready artifact.
- Deploy to staging or production.
- Run smoke checks and restart services.
- Notify the team on success or failure.
Node.js Deploy Example
git push origin main
# GitHub Actions runs tests and builds
# On success, deploy step runs:
ssh user@server "cd /var/www/my-nodejs-app \
&& git pull origin main \
&& npm ci --only=production \
&& pm2 restart my-app"
CI/CD Notes
What is CI/CD?
Think of CI/CD like an automatic quality checker plus a delivery robot for your code.
CI = Continuous Integration
Every time you push code, it automatically tests it to make sure nothing is broken.
CD = Continuous Delivery/Deployment
After tests pass, it automatically deploys your app to the server with no manual work needed.
The Simple Flow
You write code → Push to GitHub → Tests run automatically
→ If tests pass → App deploys automatically
→ If tests fail → You get notified (nothing broken in production)
Steps Involved in CI/CD
| Step | What Happens |
|---|---|
| 1. Trigger | You push code to GitHub. |
| 2. Install | Dependencies are installed (npm install). |
| 3. Lint | Code style is checked. |
| 4. Test | Unit and integration tests run. |
| 5. Build | App is built for production. |
| 6. Deploy | App is sent to your server or cloud. |
| 7. Notify | You get success or failure notification. |
GitHub Actions — How It Works
GitHub Actions uses a YAML file stored at the path below. Every time you push code, GitHub reads the file and runs the steps automatically.
your-project/
.github/
workflows/
ci-cd.yml ← this is your pipeline file
Pipeline, Unpacked
main or develop starts the
workflow. Pull requests run CI checks before merging.
npm ci for clean,
repeatable builds.
main.
GitHub Actions Example
# .github/workflows/ci-cd.yml
name: Node.js CI/CD Pipeline
on:
push:
branches: ["main", "develop"]
pull_request:
branches: ["main"]
jobs:
ci:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run lint
- run: npm test
- run: npm run build
cd:
runs-on: ubuntu-latest
needs: ci
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: "npm"
- run: npm ci --only=production
- uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
cd /var/www/my-nodejs-app
git pull origin main
npm ci --only=production
pm2 restart my-app