Script Valley
Git and GitHub Complete Course: From Beginner to Advanced
GitHub Actions and CI/CD AutomationLesson 5.4

Continuous Deployment: Automating Deployments

CD workflow, deploy on push, GitHub Pages deployment, Vercel deployment, Docker build and push, deployment environments, rollback

Continuous Deployment: Automating Deployments

Continuous Deployment (CD) extends CI by automatically deploying your application after all checks pass. GitHub Actions integrates with virtually every major hosting platform.

DiagramCI/CD Deployment Pipeline with Job Gates

IMAGE PROMPT (replace this block with your generated image):

Flat horizontal pipeline diagram on white background. Title: Continuous Deployment Pipeline with GitHub Actions. Trigger box on far left: git push to main (git icon). Five sequential job boxes connected by right arrows. Job 1: Lint — ESLint icon, fill light gray. Job 2: Test — Jest icon, fill light #3A5EFF (#e8ecff). Gate diamond between Job 2 and 3: labeled All tests pass? 80%+ coverage?. Red X branch going down labeled Pipeline stops — no deploy. Green check continues right. Job 3: Build Docker Image — Docker whale icon, fill light blue. Badge: docker build -t app:${{ github.sha }}. Job 4: Push to Registry — cloud icon, fill medium #3A5EFF. Job 5: Deploy — rocket icon, fill solid #3A5EFF white text. Deployment environment badge on Job 5: environment: production — requires manual approval (shield icon). needs: arrows shown below each job pointing to the next (needs: lint, needs: test, etc.). White background, pipeline flows left to right.

Deploying to GitHub Pages

name: Deploy to GitHub Pages

on:
  push:
    branches: [ main ]

permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/configure-pages@v4
      - uses: actions/upload-pages-artifact@v3
        with:
          path: './dist'
      - id: deployment
        uses: actions/deploy-pages@v4

Building and Pushing Docker Images

- name: Log in to Docker Hub
  uses: docker/login-action@v3
  with:
    username: ${{ secrets.DOCKER_USERNAME }}
    password: ${{ secrets.DOCKER_TOKEN }}

- name: Build and push
  uses: docker/build-push-action@v5
  with:
    push: true
    tags: username/app:latest

Deployment Gates

A common CD pattern is to require the CI workflow to pass before deployment starts. Use the needs keyword to create job dependencies:

jobs:
  test:
    runs-on: ubuntu-latest
    steps: [...]

  deploy:
    needs: test
    runs-on: ubuntu-latest
    steps: [...]

The deploy job only starts if the test job succeeds.

Up next

Advanced GitHub Actions: Reusable Workflows and Custom Actions

Sign in to track progress