Sub topic 12
Promoting through sandboxes to production with approvals
This chapter assumes you can already run a check-only deployment on a pull request and deploy on merge to one org. It also assumes you know how GitHub secrets and environments store credentials, and that you know the sandbox types (Developer, Partial Copy, Full). It extends the single-org pipeline into a chain of orgs where production waits for a human.
Why promote instead of deploying everywhere at once
A change that passes tests in a scratch org can still fail in production. Production has different data, different installed packages, and metadata that was changed by hand. Promotion exercises the same commit against progressively more realistic orgs, so failures surface in a cheap place first.
A common chain is:
- Integration or QA sandbox: receives every merge to
main. - UAT or staging sandbox: a Partial Copy or Full sandbox where testers and business users confirm the change.
- Production: receives the same commit after an approval.
The key rule is that every stage deploys the same Git commit. You promote a commit, not a branch that may have moved in the meantime.
GitHub environments as the unit of promotion
A GitHub environment is a named target (qa, uat, production) attached to a repository. It gives you three things this pipeline needs:
- Environment secrets. Each environment can hold its own
SFDX_AUTH_URL. A job that declaresenvironment: uatsees the UAT value, and a job that declaresenvironment: productionsees the production value. The workflow YAML never changes between stages. - Protection rules. Required reviewers pause a job until a listed person approves. A wait timer adds a fixed delay. Deployment branch rules restrict which branches may deploy to the environment.
- A deployment history. GitHub records each deployment against the environment, which gives you an audit trail of who approved what and when.
Create the environments under Settings > Environments. Add each org's auth URL as an environment secret with the same name, SFDX_AUTH_URL. For production, add required reviewers and limit deployment branches to main.
One reusable workflow, three stages
Copying the install, login, and deploy steps into three jobs invites drift. A reusable workflow holds the steps once. Each stage calls it with a different environment name.
Create .github/workflows/deploy-org.yml:
name: Deploy to one org
on:
workflow_call:
inputs:
environment:
required: true
type: string
test-level:
required: false
type: string
default: RunLocalTests
secrets:
SFDX_AUTH_URL:
required: true
jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Salesforce CLI
run: npm install --global @salesforce/cli
- name: Authenticate
env:
SFDX_AUTH_URL: ${{ secrets.SFDX_AUTH_URL }}
run: |
echo "$SFDX_AUTH_URL" > authurl.txt
sf org login sfdx-url --sfdx-url-file authurl.txt --alias target --set-default
rm authurl.txt
- name: Deploy
run: >
sf project deploy start
--source-dir force-app
--test-level ${{ inputs.test-level }}
--target-org target
--wait 60Now create .github/workflows/promote.yml, which chains the stages with needs:
name: Promote
on:
push:
branches: [main]
concurrency:
group: promote
cancel-in-progress: false
jobs:
qa:
uses: ./.github/workflows/deploy-org.yml
with:
environment: qa
test-level: RunLocalTests
secrets: inherit
uat:
needs: qa
uses: ./.github/workflows/deploy-org.yml
with:
environment: uat
test-level: RunLocalTests
secrets: inherit
production:
needs: uat
uses: ./.github/workflows/deploy-org.yml
with:
environment: production
test-level: RunLocalTests
secrets: inheritHow this behaves:
needsmakes a stage start only if the previous stage succeeded. A failed QA deployment means UAT and production never start.- The
environmentis declared inside the called workflow's job. That is where GitHub evaluates secrets and protection rules, so the production job pauses for approval there. secrets: inheritpasses the caller's secrets to the called workflow. Environment secrets are resolved from the job's ownenvironmentsetting, so each stage still gets its own auth URL.- The
concurrencygroup queues runs. Without it, two quick merges could have run N in production while run N+1 is still in QA.cancel-in-progress: falseis deliberate, because cancelling a deployment halfway is worse than waiting.
What the approval gate really approves
When the production job is reached, GitHub marks it as waiting and notifies the required reviewers. A reviewer can see the commit, the workflow run, and the results of earlier stages, then approve or reject. Only approval lets the job start and read the production secret.
Three practical points follow:
- Reviewers are chosen per environment, so QA can have none, UAT can have a tester, and production can have a release manager.
- You can block the person who triggered the run from approving their own deployment, using the "prevent self-review" option. This gives you separation of duties.
- A waiting job holds its place in the concurrency group. If approval sits for a day, newer runs queue behind it. Decide who owns the approval, and how fast they must respond.
Choosing test levels per stage
The test level does not have to be identical everywhere. A reasonable pattern:
| Stage | Test level | Reason |
|---|---|---|
| QA | `RunLocalTests` | Fast feedback and the same check production will apply |
| UAT | `RunLocalTests` | Confirms the result on more realistic data |
| Production | `RunLocalTests` | Salesforce requires tests when deploying Apex to production |
Sandboxes accept NoTestRun, which is faster, but then the first full test run happens at the end of the chain. If you want the production run to be quick, validate earlier and use a quick deploy, covered in its own chapter.
Common errors
- Production deploys without waiting. The job's
environmentvalue does not match the environment name, or no reviewers are configured. The name is case sensitive in practice, so check it against the Settings page. - "Input required and not supplied" or an empty auth URL. The secret was created at repository level in one place and environment level in another, or it was never added to the new environment. Add
SFDX_AUTH_URLto each environment. - Authentication fails after a sandbox refresh. A refreshed sandbox is a new org, so the old auth URL stops working. Generate a new URL with
sf org display --verbose --target-org <alias>and update the environment secret. - Production fails on something QA passed. The orgs have drifted, for example a field created by hand in production. Compare metadata and fix the source or the org. Do not lower the test level to get past it.
- Reviewers approve a stale commit. Because runs queue, the commit under review may no longer be the newest on
main. That is expected: you approve the commit shown on that run.
Exercise
Your pipeline has jobs qa, uat, and production. Production has required reviewers, but a teammate reports that production deployed immediately after UAT, with no approval prompt. Name two things you would check, and say which setting of the called workflow controls which secret the job receives.
Show answer
Check that the job in the called workflow sets environment: ${{ inputs.environment }} and that the caller passes environment: production with the exact environment name, and check that the production environment actually has required reviewers configured (and that your GitHub plan supports them for this repository). The environment key on the job controls which secrets the job receives, because GitHub resolves environment secrets from that job's environment.