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.
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 deployDo this now
Add deploy-staging job on push to main after tests pass.
Protection rules
Production: required reviewers, wait timer, branch restriction to main only.
Do this now
Add production environment with required reviewer (yourself for lab).
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.