Manuals / CI/CD Pipelines / Ch 8

C · Speed & ScaleIntermediate60 min read

8. Environments, deployments & approvals

CI/CD Pipelines · 48 pages source format

GitHub Environments model staging and production. Protection rules, required reviewers, deployment branches.

What you'll learn

  • Environment config
  • Deployment jobs
  • Protection rules
  • Deployment history

Create environments

Settings → Environments → staging, production. Different secrets per env.

Do this now

Create staging environment. Add STAGING_URL secret.

Clear?

Deploy job

job deploy needs: test, environment: staging, runs deploy script or GitHub Pages action.

deploy-staging:
  needs: test
  runs-on: ubuntu-latest
  environment: staging
  steps:
    - uses: actions/checkout@v4
    - run: npm run build
    - name: Deploy
      run: echo "Deploy to staging" # replace with real deploy

Do this now

Add deploy-staging job on push to main after tests pass.

Clear?

Protection rules

Production: required reviewers, wait timer, branch restriction to main only.

Do this now

Add production environment with required reviewer (yourself for lab).

Clear?

Deployment URL

environment url shows in PR deployment history — links to staging site.

Do this now

Set environment URL in config. Verify appears in Deployments tab.

Clear?

Checklist