Skip to content
Latchkey

How to Deploy to Multiple Environments Sequentially in GitHub Actions

Promoting a build through dev then staging then prod means each stage must wait on a clean result from the last.

Create one job per environment and wire them with needs so they run in strict order, each gated by an environment.

Steps

  • Create a job per environment with its environment block.
  • Chain them with needs so prod waits on staging, staging on dev.
  • Reuse the same deploy step across jobs to keep them consistent.
  • Add required reviewers on the prod environment for a final gate.

Workflow

.github/workflows/sequential-deploy.yml
name: Sequential Deploy
on:
  push:
    branches: [main]
jobs:
  dev:
    runs-on: ubuntu-latest
    environment: dev
    steps: [{ run: ./deploy.sh dev }]
  staging:
    needs: dev
    runs-on: ubuntu-latest
    environment: staging
    steps: [{ run: ./deploy.sh staging }]
  prod:
    needs: staging
    runs-on: ubuntu-latest
    environment: prod
    steps: [{ run: ./deploy.sh prod }]

Notes

  • A required-reviewer environment pauses the chain until someone approves prod.
  • Latchkey managed runners run each promotion stage cheaper and self-heal between environments.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →