Next.js
/Intermediate
CI/CD Pipelines
Definition
Continuous Integration & Continuous Deployment: Automated workflows that test, build, and deploy your code every time a developer commits changes to the repository.
Explain Like I'm New
Without CI/CD: A developer finishes a feature, pushes code, logs into the production server, types `npm run build`, hopes it doesn't crash, and restarts the server. With CI/CD: A developer pushes code. A robot automatically runs all tests. If tests pass, the robot builds the code and deploys it to the server safely while the developer goes to get coffee.
Real World Example
Using GitHub Actions. Every time a Pull Request is opened, a script spins up a server, runs ESLint, runs Jest tests, and runs Cypress E2E tests. If any test fails, the 'Merge' button is physically blocked.
Common Use Cases
- •Team collaboration
- •Preventing production bugs
- •Automated deployments
Terminal Output
bash / terminal
# .github/workflows/main.yml (GitHub Actions Pipeline)
name: Next.js CI
# Triggers whenever code is pushed to the main branch
on:
push:
branches: [ main ]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Run Linters
run: npm run lint
- name: Run Unit Tests
run: npm test
- name: Verify Next.js Build succeeds
run: npm run build
Interview Questions
basic
- What does the 'CI' stand for in CI/CD?
intermediate
- Why should you run `npm run lint` and `npm run build` in your CI pipeline before deploying?