Continuous Integration (CI) and Continuous Deployment (CD) are at the heart of modern DevOps. GitHub Actions enables engineers to automate builds, tests, and deployments across multiple environments without relying on third-party CI/CD tools.
Scenario: Deploy a Node.js web app to staging and production using separate branches.
Workflow Steps:
develop branch, production if main.name: CI/CD Pipeline
on:
push:
branches:
- develop
- main
jobs:
build-test-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Dependencies
run: npm ci
- name: Run Tests
run: npm test
- name: Build App
run: npm run build
- name: Deploy to Staging
if: github.ref == 'refs/heads/develop'
run: ./deploy-staging.sh
- name: Deploy to Production
if: github.ref == 'refs/heads/main'
run: ./deploy-production.sh
- name: Notify Team
uses: slackapi/slack-github-action@v1
with:
channel-id: 'C0123456'
text: 'Deployment completed!'
A well-designed CI/CD pipeline with GitHub Actions reduces human error, accelerates delivery, and ensures consistent deployments. It’s a cornerstone for any DevOps workflow, allowing engineers to focus on delivering features instead of manual processes.