Secrets scoped to a deploy target
An environment in GitHub Actions is a named deploy target (staging, production, preview). Each environment can have its own secrets, variables, protection rules, and deployment URL.
The classic shape:
stagingenvironment withSTAGING_DB_URL,STAGING_API_KEY.productionenvironment withPROD_DB_URL,PROD_API_KEY, plus required reviewers.- Same workflow file, two jobs — each scoped to one environment.
Why environments matter
- Blast radius — a workflow run that targets
stagingliterally cannot readproductionsecrets. The walls are real. - Approvals — environments support 'required reviewers' (manual approval) and 'wait timer' (cooling period). The deploy job pauses until satisfied.
- Branch policies — restrict an environment to specific branches (
mainonly for prod). - Visibility — the Deployments tab shows which commit is currently in each environment, with link to the run.