Last delivery practice. On every push to main, deploy to staging, and run a smoke test. Then deploy the same build to production, behind the production environment's approval.
The staging job deploys the build named after the commit, and runs a smoke test. The production job needs staging, and uses the production environment, where you'd add required reviewers. Both jobs use the same SHA tag, so production gets exactly what staging tested.
.github/workflows/delivery.ymlyaml
name: Deliveryon: push: branches: [main]jobs: staging: runs-on: ubuntu-latest environment: staging steps: - run: echo "Deploy sha-${GITHUB_SHA::7} to staging" - run: echo "Smoke test on staging passed" production: needs: staging runs-on: ubuntu-latest environment: production steps: - run: echo "Deploy sha-${GITHUB_SHA::7} to production"
Our helper runs staging, then production. Both deploy lines show the same SHA, so the artifact is built once, and promoted. On GitHub, the production job would wait here for an approval.
Terminal
run-steps .github/workflows/delivery.yml | grep -vE "^Workflow|✓"Job: staging Environment: staging Deploy sha-7418016 to staging Smoke test on staging passed Job succeededJob: production Environment: production Deploy sha-7418016 to production Job succeeded
Two pushes close together could start two production deploys at once, and they might fight. Add concurrency with a group named after the environment, so deploys queue up, one after another. For deploys, don't cancel the run in progress. Let it finish, then start the next.