How do environments relate to GitHub Deployments and the deployments API?
AdvancedConceptSecrets, Variables, Environments & Permissions
Answer
Every job with environment creates a deployment object for that environment and ref, and updates deployment statuses (in_progress, success, failure) automatically. The environments page and PR timeline show history ("deployed to staging 2 hours ago"), and the API (GET /repos/{owner}/{repo}/deployments?environment=prod) lets tooling find what SHA is in prod. A side effect: jobs that use an environment only to read its secrets still create deployment records, which clutters the history, so give such jobs a separate environment name (for example prod-readonly).
More on Secrets, Variables, Environments & Permissions
Where can secrets be defined, and what is the precedence?BeginnerHow are secrets protected in transit and in logs, and what are the limits?IntermediateAre secrets available to every step automatically?BeginnerWhy is it a bad idea to store structured data like JSON or a whole `.env` file as one secret?IntermediateWhat is an environment, and which protection rules can it have?BeginnerWhen does a job wait for environment approval, and what does the reviewer see?Intermediate