GitHub Actions: Environments and Approvals
An environment is a named target for a deploy, like staging or production. An approval is a human click that lets a deploy go ahead.
Deploy to staging, with no approval
Staging deploys on its own, so a change can be checked at once.
deploy-staging:
environment: stagingDeploy to production, with an approval
The job names the production environment. GitHub pauses it until a reviewer approves.
deploy-production:
environment: productionWhat the reviewer clicks
The run page shows a Review deployments button. The reviewer clicks it, then Approve and deploy.
Review deployments -> Approve and deployExample
name: Environments demo
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '24'
- run: npm test
deploy-staging:
runs-on: ubuntu-latest
needs: test
environment: staging
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '24'
- run: npm run build
- run: echo "Deployed to staging."
deploy-production:
runs-on: ubuntu-latest
needs: deploy-staging
environment: production
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '24'
- run: npm run build
- run: echo "Deployed to production."Key points
- Use an environment to name where a deploy goes, like staging or production.
- Staging is a test copy of the live site, for checking a change before readers see it.
- Production is the live site that readers actually use.
- An environment can need a human approval before any job using it runs.
- GitHub pauses the job and waits for a reviewer to click Approve and deploy.
- An environment can hold its own secrets, separate from the repository secrets.
In this example, the test job runs the tests first. The staging job needs the test job, so it builds the site and deploys to staging with no approval. The production job needs the staging job, and it names the production environment. GitHub pauses it until a reviewer clicks Approve and deploy on the run page. Then the job builds the site and deploys to production.
Note
The staging and production environments are created in repo Settings under Environments. The coordinator creates both at verification time.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What happens when a job names a production environment that needs approval?