docs/github-environments.md
This document provides step-by-step instructions for setting up GitHub Environments for production and staging deployments.
GitHub Environments allow you to:
productionmain branch only
mainAdd production-specific secrets:
DOCKER_REGISTRY_TOKEN - Production registry accessDEPLOY_KEY - Production deployment keyAPI_KEYS - Production API keysstagingnext branch
nextAdd staging-specific secrets:
DOCKER_REGISTRY_TOKEN - Staging registry accessDEPLOY_KEY - Staging deployment keyAPI_KEYS - Staging/test API keysModify your deployment workflows to use environments:
# Example: .github/workflows/deploy-production.yml
name: Deploy to Production
on:
push:
branches: [main]
tags: ['v*']
jobs:
deploy:
runs-on: ubuntu-latest
environment: production # <- This connects to the environment
steps:
- uses: actions/checkout@v4
- name: Deploy
run: |
echo "Deploying to production..."
# Use secrets like: ${{ secrets.DEPLOY_KEY }}
# Example: .github/workflows/deploy-staging.yml
name: Deploy to Staging
on:
push:
branches: [next]
jobs:
deploy:
runs-on: ubuntu-latest
environment: staging # <- This connects to the environment
steps:
- uses: actions/checkout@v4
- name: Deploy
run: |
echo "Deploying to staging..."
# Use secrets like: ${{ secrets.DEPLOY_KEY }}
After setup, verify:
Reference environment-specific secrets in your workflows:
- name: Deploy Application
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
API_KEY: ${{ secrets.API_KEY }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
run: |
./deploy.sh
Environment not found: Ensure the workflow references the exact environment name (case-sensitive)
Secret not available: Verify the secret exists in the specific environment, not at repository level
Branch restriction failed: Check that the deployment branch matches the environment's branch protection rules
Approval hanging: Ensure required reviewers have repository access and notification settings enabled