Git Notes
Continuous Integration and Continuous Deployment (CI/CD) is the backbone of modern software delivery. CI ensures that every code change is automatically...
Continuous Integration and Continuous Deployment (CI/CD) is the backbone of modern software delivery. CI ensures that every code change is automatically tested and validated, while CD automates the deployment of validated code to production. GitHub Actions provides a native, powerful CI/CD platform built directly into your repository — no external tools needed.
Understanding CI/CD
Continuous Integration (CI) is the practice of frequently merging developer code into a shared repository, with each merge triggering automated builds and tests. The goal is to catch integration problems early when they are cheap to fix.
Continuous Deployment (CD) takes validated code and automatically deploys it to production. Every change that passes CI goes live without manual intervention.
Continuous Delivery (also CD) is the middle ground — code is automatically prepared for deployment but requires manual approval to go live.
Building a Complete CI/CD Pipeline
Pipeline Stages Explained
Stage 1: Code Quality
Before running expensive tests, verify code quality:
- Linting catches style violations and potential bugs
- Type checking (TypeScript) catches type errors at build time
- Formatting ensures consistent code style
If linting fails, the pipeline stops immediately — no point testing code that does not meet standards.
Stage 2: Testing
Run your test suite at various levels:
- Unit tests (fastest, most numerous)
- Integration tests (moderate speed)
- End-to-end tests (slowest, fewest)
Stage 3: Build
Compile the application into deployment artifacts:
- Bundle JavaScript/TypeScript
- Optimize assets (images, CSS)
- Generate static pages
- Create Docker images
Stage 4: Deploy
Place the built artifacts on servers:
- Upload to cloud hosting (Vercel, Netlify, AWS)
- Push Docker images to registries
- Update Kubernetes deployments
- Trigger serverless function updates
Environment Protection
GitHub Actions environments add safety to deployments:
deploy:
environment:
name: production
url: https://myapp.comConfigure environment protection rules:
- Required reviewers — Someone must approve before deployment
- Wait timer — Delay deployment by N minutes (cancel window)
- Branch restrictions — Only deploy from specific branches
Secrets Management
Store sensitive values securely:
steps:
- name: Deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
run: npm run deploySecrets are encrypted, never exposed in logs, and can be scoped to specific environments.
Parallel vs Sequential Jobs
Run independent jobs simultaneously to save time:
Monitoring and Notifications
Alert the team when pipelines fail:
- name: Notify on failure
if: failure()
uses: slackapi/slack-github-action@v1
with:
payload: |
{"text": "CI/CD failed on ${{ github.ref }}"}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}Rollback Strategy
Include rollback capability in your pipeline:
rollback:
if: failure() && needs.deploy.result == 'failure'
needs: deploy
runs-on: ubuntu-latest
steps:
- name: Rollback to previous version
run: |
# Revert to the last known good deployment
aws ecs update-service --desired-count 0 --service new-version
aws ecs update-service --desired-count 2 --service stable-versionKey Takeaways
CI/CD with GitHub Actions automates the entire path from code commit to production deployment. Structure your pipeline in stages — quality checks, testing, building, and deploying — with each stage acting as a gate. Use environments for deployment protection, secrets for sensitive configuration, and parallel jobs for speed. A well-designed pipeline gives teams confidence to deploy frequently, knowing that automation catches problems before users encounter them.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for CI/CD with GitHub Actions.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Git & GitHub topic.
Search Terms
git-github, git & github, git, github, actions, with, ci/cd with github actions
Related Git & GitHub Topics